mirror of
https://github.com/fosrl/olm.git
synced 2026-02-08 05:56:41 +00:00
12
api/api.go
12
api/api.go
@@ -102,6 +102,14 @@ func NewAPISocket(socketPath string) *API {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewAPIStub() *API {
|
||||||
|
s := &API{
|
||||||
|
peerStatuses: make(map[int]*PeerStatus),
|
||||||
|
}
|
||||||
|
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
// SetHandlers sets the callback functions for handling API requests
|
// SetHandlers sets the callback functions for handling API requests
|
||||||
func (s *API) SetHandlers(
|
func (s *API) SetHandlers(
|
||||||
onConnect func(ConnectionRequest) error,
|
onConnect func(ConnectionRequest) error,
|
||||||
@@ -117,6 +125,10 @@ func (s *API) SetHandlers(
|
|||||||
|
|
||||||
// Start starts the HTTP server
|
// Start starts the HTTP server
|
||||||
func (s *API) Start() error {
|
func (s *API) Start() error {
|
||||||
|
if s.socketPath == "" && s.addr == "" {
|
||||||
|
return fmt.Errorf("either socketPath or addr must be provided to start the API server")
|
||||||
|
}
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.HandleFunc("/connect", s.handleConnect)
|
mux.HandleFunc("/connect", s.handleConnect)
|
||||||
mux.HandleFunc("/status", s.handleStatus)
|
mux.HandleFunc("/status", s.handleStatus)
|
||||||
|
|||||||
@@ -111,6 +111,9 @@ func Init(ctx context.Context, config GlobalConfig) {
|
|||||||
apiServer = api.NewAPI(config.HTTPAddr)
|
apiServer = api.NewAPI(config.HTTPAddr)
|
||||||
} else if config.SocketPath != "" {
|
} else if config.SocketPath != "" {
|
||||||
apiServer = api.NewAPISocket(config.SocketPath)
|
apiServer = api.NewAPISocket(config.SocketPath)
|
||||||
|
} else {
|
||||||
|
// this is so is not null but it cant be started without either the socket path or http addr
|
||||||
|
apiServer = api.NewAPIStub()
|
||||||
}
|
}
|
||||||
|
|
||||||
apiServer.SetVersion(config.Version)
|
apiServer.SetVersion(config.Version)
|
||||||
@@ -304,8 +307,13 @@ func StartTunnel(config TunnelConfig) {
|
|||||||
|
|
||||||
tdev, err = func() (tun.Device, error) {
|
tdev, err = func() (tun.Device, error) {
|
||||||
if config.FileDescriptorTun != 0 {
|
if config.FileDescriptorTun != 0 {
|
||||||
|
if runtime.GOOS == "android" { // otherwise we get a permission denied
|
||||||
|
theTun, _, err := tun.CreateUnmonitoredTUNFromFD(int(config.FileDescriptorTun))
|
||||||
|
return theTun, err
|
||||||
|
} else {
|
||||||
return olmDevice.CreateTUNFromFD(config.FileDescriptorTun, config.MTU)
|
return olmDevice.CreateTUNFromFD(config.FileDescriptorTun, config.MTU)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
var ifName = interfaceName
|
var ifName = interfaceName
|
||||||
if runtime.GOOS == "darwin" { // this is if we dont pass a fd
|
if runtime.GOOS == "darwin" { // this is if we dont pass a fd
|
||||||
ifName, err = network.FindUnusedUTUN()
|
ifName, err = network.FindUnusedUTUN()
|
||||||
|
|||||||
Reference in New Issue
Block a user