-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3e2781
commit 9c2bfd5
Showing
3 changed files
with
57 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package tailscale | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"path/filepath" | ||
|
||
"github.com/almeidapaulopt/tsdproxy/internal/core" | ||
"tailscale.com/tsnet" | ||
) | ||
|
||
type TsNetServer struct { | ||
TsServer *tsnet.Server | ||
} | ||
|
||
func NewTsNetServer(hostname string, config *core.Config, logger *core.Logger) *TsNetServer { | ||
return &TsNetServer{ | ||
&tsnet.Server{ | ||
Hostname: hostname, | ||
AuthKey: config.AuthKey, | ||
Dir: filepath.Join(config.DataDir, hostname), | ||
Ephemeral: true, | ||
Logf: func(format string, args ...any) { | ||
logger.Info().Msgf(format, args...) | ||
}, | ||
UserLogf: func(format string, args ...any) { | ||
logger.Info().Msgf(format, args...) | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (tn *TsNetServer) Close() error { | ||
return tn.TsServer.Close() | ||
} | ||
|
||
func (tn *TsNetServer) Start(ctx context.Context) error { | ||
if err := tn.TsServer.Start(); err != nil { | ||
return fmt.Errorf("error starting server: %w", err) | ||
} | ||
|
||
// Wait for tailscale to come up... | ||
if _, err := tn.TsServer.Up(ctx); err != nil { | ||
return fmt.Errorf("error to come up server: %w", err) | ||
} | ||
|
||
return tn.TsServer.Start() | ||
} |