mirror of
https://github.com/coder/coder.git
synced 2026-11-03 14:21:04 +08:00
47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package tailnet
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"cdr.dev/slog/v3"
|
|
"github.com/coder/coder/v2/apiversion"
|
|
agpl "github.com/coder/coder/v2/tailnet"
|
|
)
|
|
|
|
type ClientService struct {
|
|
*agpl.ClientService
|
|
}
|
|
|
|
// NewClientService returns a ClientService based on the given Coordinator pointer. The pointer is
|
|
// loaded on each processed connection.
|
|
func NewClientService(options agpl.ClientServiceOptions) (*ClientService, error) {
|
|
s, err := agpl.NewClientService(options)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &ClientService{ClientService: s}, nil
|
|
}
|
|
|
|
func (s *ClientService) ServeMultiAgentClient(ctx context.Context, version string, conn net.Conn, id uuid.UUID) error {
|
|
major, _, err := apiversion.Parse(version)
|
|
if err != nil {
|
|
s.Logger.Warn(ctx, "serve client called with unparsable version", slog.Error(err))
|
|
return err
|
|
}
|
|
switch major {
|
|
case 2:
|
|
streamID := agpl.StreamID{
|
|
Name: id.String(),
|
|
ID: id,
|
|
Auth: agpl.SingleTailnetCoordinateeAuth{},
|
|
}
|
|
return s.ServeConnV2(ctx, conn, streamID)
|
|
default:
|
|
s.Logger.Warn(ctx, "serve client called with unsupported version", slog.F("version", version))
|
|
return agpl.ErrUnsupportedVersion
|
|
}
|
|
}
|