Skip to content
This repository has been archived by the owner on Feb 3, 2025. It is now read-only.

Commit

Permalink
refactor: Added BareCoordinator interface
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Kosiewski <[email protected]>
  • Loading branch information
Thomas Kosiewski committed Jul 17, 2024
1 parent 658a80b commit 135fdec
Show file tree
Hide file tree
Showing 286 changed files with 32,719 additions and 11,094 deletions.
64 changes: 11 additions & 53 deletions coordinator.go
Original file line number Diff line number Diff line change
@@ -1,61 +1,19 @@
package tunnel

import (
"context"
"net/http"
"time"

"tailscale.com/tailcfg"
"tailscale.com/types/key"
"github.com/loft-sh/tunnel/handlers"
)

// Coordinator is the interface that wraps the coordinator methods.
type Coordinator interface {
// ControlKey returns the control key for coordinator.
ControlKey() key.MachinePrivate
// LegacyControlKey returns the legacy control key for coordinator.
LegacyControlKey() key.MachinePrivate

// RegisterMachine is responsible for registering the machine with the
// coordinator. It returns the registration response from the coordinator
// and an error if any.
RegisterMachine(ctx context.Context, req tailcfg.RegisterRequest, peerPublicKey key.MachinePublic) (tailcfg.RegisterResponse, error)

// DerpMap returns the DERP map from the coordinator.
DerpMap(ctx context.Context) (tailcfg.DERPMap, error)
// BareCoordinator is an interface encorfcing the bare handlers that need to be
// defined for the Tailscale control server to work.
type BareCoordinator = handlers.Coordinator

// KeepAliveInterval is the keep alive interval used by the coordinator to
// periodically send keep alive messages to the tailscale client via the
// long poll NetMap request.
KeepAliveInterval() time.Duration
// NetMap handles the netmap polling request from a tailscale client. It
// returns a channel of netmap responses and a channel of errors.
//
// - If the request is a streaming one, the channels are not to be closed
// and new responses shall be sent via the channels.
//
// - If the request is a non-streaming one, the channels are to be closed
// after the first response is sent.
//
// - If the request gets closed or cancelled by the tailscale client, the
// context will be cancelled and the channels shall not be used anymore.
NetMap(ctx context.Context, req tailcfg.MapRequest, peerPublicKey key.MachinePublic) (chan tailcfg.MapResponse, chan error)

// SetDNS handles the DNS setting request from a tailscale client.
SetDNS(ctx context.Context, req tailcfg.SetDNSRequest, peerPublicKey key.MachinePublic) (tailcfg.SetDNSResponse, error)

// HealthChange handles the health change request from a tailscale client.
HealthChange(ctx context.Context, req tailcfg.HealthChangeRequest)

// IDToken handles the ID token request from a tailscale client.
IDToken(ctx context.Context, req tailcfg.TokenRequest, peerPublicKey key.MachinePublic) (tailcfg.TokenResponse, error)
// Coordinator is the interface enforcing all handler functions to be defined.
type Coordinator interface {
BareCoordinator

// SSHAction handles the SSH action request from a tailscale client.
//
// It returns the SSH action response and an error if any. Additionally, the
// entire request is provided to the implementation as the request may
// contain additional information that is not known to the library.
//
// This method handles all noise requests to the `/ssh/action/*` pattern.
SSHAction(r *http.Request, peerPublicKey key.MachinePublic) (tailcfg.SSHAction, error)
handlers.DNSSetter
handlers.HealthChanger
handlers.IDTokenRequestHandler
handlers.SSHActioner
}
27 changes: 14 additions & 13 deletions examples/coordinator/go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module github.com/loft-sh/tunnel/examples/coordinator

go 1.22.2
go 1.22.5

require (
github.com/go-chi/chi/v5 v5.0.12
github.com/go-chi/chi/v5 v5.1.0
github.com/invopop/jsonschema v0.12.0
github.com/loft-sh/tunnel v0.1.0
github.com/metal-stack/go-ipam v1.13.0
tailscale.com v1.64.2
tailscale.com v1.68.2
)

require (
Expand All @@ -16,7 +16,7 @@ require (
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/coreos/go-iptables v0.7.0 // indirect
github.com/coreos/go-iptables v0.7.1-0.20240112124308-65c67c9f46e6 // indirect
github.com/coreos/go-semver v0.3.1 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/dblohm7/wingoes v0.0.0-20240119213807-a09d6be7affa // indirect
Expand All @@ -27,11 +27,11 @@ require (
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/nftables v0.1.1-0.20230115205135-9aa6fdf5a28c // indirect
github.com/google/nftables v0.2.1-0.20240414091927-5e242ec57806 // indirect
github.com/jmoiron/sqlx v1.3.5 // indirect
github.com/josharian/native v1.1.1-0.20230202152459-5c7d0dd6ab86 // indirect
github.com/jsimonetti/rtnetlink v1.4.0 // indirect
github.com/klauspost/compress v1.17.8 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mdlayher/netlink v1.7.2 // indirect
Expand All @@ -57,13 +57,14 @@ require (
go.uber.org/zap v1.26.0 // indirect
go4.org/mem v0.0.0-20240501181205-ae6ca9944745 // indirect
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.17.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
golang.zx2c4.com/wireguard/windows v0.5.3 // indirect
google.golang.org/genproto v0.0.0-20240102182953-50ed04b92917 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240102182953-50ed04b92917 // indirect
Expand Down
Loading

0 comments on commit 135fdec

Please sign in to comment.