chore: remove tailnet from agent API and rename client API to tailnet (#11303)

Refactors our DRPC service definitions slightly.

In the previous version, I inserted the RPCs from the tailnet proto directly into the Agent service.  This makes things hard to deal with because DRPC then generates a new set of methods with new interfaces with the `DRPCAgent_` prefixed.  Since you can't have a single method that takes different argument types, we couldn't reuse the implementation of those RFCs without a lot of extra classes and pass-thru methods.

Instead, the "right" way to do it is to integrate at the DRPC layer.  So, we have two DRPC services available over the Agent websocket, and register them both on the DRPC `mux`.

Since the tailnet proto RPC service is now for both clients and agents, I renamed some things to clarify and shorten.

This PR also removes the `TailnetAPI` implementation from the `agentapi` package, and the next PR in the stack replaces it with the implementation from the `tailnet` package.
This commit is contained in:
Spike Curtis 2024-01-02 10:02:45 +04:00 committed by GitHub
parent 65290997c1
commit 25f2abf9ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 97 additions and 328 deletions

View File

@ -2568,7 +2568,7 @@ var file_agent_proto_agent_proto_rawDesc = []byte{
0x41, 0x42, 0x4c, 0x45, 0x44, 0x10, 0x01, 0x12, 0x10, 0x0a, 0x0c, 0x49, 0x4e, 0x49, 0x54, 0x49, 0x41, 0x42, 0x4c, 0x45, 0x44, 0x10, 0x01, 0x12, 0x10, 0x0a, 0x0c, 0x49, 0x4e, 0x49, 0x54, 0x49,
0x41, 0x4c, 0x49, 0x5a, 0x49, 0x4e, 0x47, 0x10, 0x02, 0x12, 0x0b, 0x0a, 0x07, 0x48, 0x45, 0x41, 0x41, 0x4c, 0x49, 0x5a, 0x49, 0x4e, 0x47, 0x10, 0x02, 0x12, 0x0b, 0x0a, 0x07, 0x48, 0x45, 0x41,
0x4c, 0x54, 0x48, 0x59, 0x10, 0x03, 0x12, 0x0d, 0x0a, 0x09, 0x55, 0x4e, 0x48, 0x45, 0x41, 0x4c, 0x4c, 0x54, 0x48, 0x59, 0x10, 0x03, 0x12, 0x0d, 0x0a, 0x09, 0x55, 0x4e, 0x48, 0x45, 0x41, 0x4c,
0x54, 0x48, 0x59, 0x10, 0x04, 0x32, 0xb2, 0x07, 0x0a, 0x05, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x12, 0x54, 0x48, 0x59, 0x10, 0x04, 0x32, 0xf6, 0x05, 0x0a, 0x05, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x12,
0x4b, 0x0a, 0x0b, 0x47, 0x65, 0x74, 0x4d, 0x61, 0x6e, 0x69, 0x66, 0x65, 0x73, 0x74, 0x12, 0x22, 0x4b, 0x0a, 0x0b, 0x47, 0x65, 0x74, 0x4d, 0x61, 0x6e, 0x69, 0x66, 0x65, 0x73, 0x74, 0x12, 0x22,
0x2e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2e, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2e, 0x76, 0x32, 0x2e, 0x2e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2e, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2e, 0x76, 0x32, 0x2e,
0x47, 0x65, 0x74, 0x4d, 0x61, 0x6e, 0x69, 0x66, 0x65, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x47, 0x65, 0x74, 0x4d, 0x61, 0x6e, 0x69, 0x66, 0x65, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65,
@ -2615,22 +2615,10 @@ var file_agent_proto_agent_proto_rawDesc = []byte{
0x61, 0x74, 0x63, 0x68, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4c, 0x6f, 0x67, 0x73, 0x52, 0x65, 0x61, 0x74, 0x63, 0x68, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4c, 0x6f, 0x67, 0x73, 0x52, 0x65,
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2e, 0x61, 0x67, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2e, 0x61, 0x67,
0x65, 0x6e, 0x74, 0x2e, 0x76, 0x32, 0x2e, 0x42, 0x61, 0x74, 0x63, 0x68, 0x43, 0x72, 0x65, 0x61, 0x65, 0x6e, 0x74, 0x2e, 0x76, 0x32, 0x2e, 0x42, 0x61, 0x74, 0x63, 0x68, 0x43, 0x72, 0x65, 0x61,
0x74, 0x65, 0x4c, 0x6f, 0x67, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x56, 0x74, 0x65, 0x4c, 0x6f, 0x67, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x27,
0x0a, 0x0e, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x44, 0x45, 0x52, 0x50, 0x4d, 0x61, 0x70, 0x73, 0x5a, 0x25, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x64,
0x12, 0x27, 0x2e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2e, 0x74, 0x61, 0x69, 0x6c, 0x6e, 0x65, 0x74, 0x65, 0x72, 0x2f, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2f, 0x76, 0x32, 0x2f, 0x61, 0x67, 0x65, 0x6e,
0x2e, 0x76, 0x32, 0x2e, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x44, 0x45, 0x52, 0x50, 0x4d, 0x61, 0x74, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x70, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x63, 0x6f, 0x64, 0x65,
0x72, 0x2e, 0x74, 0x61, 0x69, 0x6c, 0x6e, 0x65, 0x74, 0x2e, 0x76, 0x32, 0x2e, 0x44, 0x45, 0x52,
0x50, 0x4d, 0x61, 0x70, 0x30, 0x01, 0x12, 0x62, 0x0a, 0x11, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x69,
0x6e, 0x61, 0x74, 0x65, 0x54, 0x61, 0x69, 0x6c, 0x6e, 0x65, 0x74, 0x12, 0x23, 0x2e, 0x63, 0x6f,
0x64, 0x65, 0x72, 0x2e, 0x74, 0x61, 0x69, 0x6c, 0x6e, 0x65, 0x74, 0x2e, 0x76, 0x32, 0x2e, 0x43,
0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
0x1a, 0x24, 0x2e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2e, 0x74, 0x61, 0x69, 0x6c, 0x6e, 0x65, 0x74,
0x2e, 0x76, 0x32, 0x2e, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x52, 0x65,
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x28, 0x01, 0x30, 0x01, 0x42, 0x27, 0x5a, 0x25, 0x67, 0x69,
0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2f, 0x63,
0x6f, 0x64, 0x65, 0x72, 0x2f, 0x76, 0x32, 0x2f, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2f, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
} }
var ( var (
@ -2688,9 +2676,6 @@ var file_agent_proto_agent_proto_goTypes = []interface{}{
(*durationpb.Duration)(nil), // 37: google.protobuf.Duration (*durationpb.Duration)(nil), // 37: google.protobuf.Duration
(*proto.DERPMap)(nil), // 38: coder.tailnet.v2.DERPMap (*proto.DERPMap)(nil), // 38: coder.tailnet.v2.DERPMap
(*timestamppb.Timestamp)(nil), // 39: google.protobuf.Timestamp (*timestamppb.Timestamp)(nil), // 39: google.protobuf.Timestamp
(*proto.StreamDERPMapsRequest)(nil), // 40: coder.tailnet.v2.StreamDERPMapsRequest
(*proto.CoordinateRequest)(nil), // 41: coder.tailnet.v2.CoordinateRequest
(*proto.CoordinateResponse)(nil), // 42: coder.tailnet.v2.CoordinateResponse
} }
var file_agent_proto_agent_proto_depIdxs = []int32{ var file_agent_proto_agent_proto_depIdxs = []int32{
1, // 0: coder.agent.v2.WorkspaceApp.sharing_level:type_name -> coder.agent.v2.WorkspaceApp.SharingLevel 1, // 0: coder.agent.v2.WorkspaceApp.sharing_level:type_name -> coder.agent.v2.WorkspaceApp.SharingLevel
@ -2734,20 +2719,16 @@ var file_agent_proto_agent_proto_depIdxs = []int32{
22, // 38: coder.agent.v2.Agent.UpdateStartup:input_type -> coder.agent.v2.UpdateStartupRequest 22, // 38: coder.agent.v2.Agent.UpdateStartup:input_type -> coder.agent.v2.UpdateStartupRequest
24, // 39: coder.agent.v2.Agent.BatchUpdateMetadata:input_type -> coder.agent.v2.BatchUpdateMetadataRequest 24, // 39: coder.agent.v2.Agent.BatchUpdateMetadata:input_type -> coder.agent.v2.BatchUpdateMetadataRequest
27, // 40: coder.agent.v2.Agent.BatchCreateLogs:input_type -> coder.agent.v2.BatchCreateLogsRequest 27, // 40: coder.agent.v2.Agent.BatchCreateLogs:input_type -> coder.agent.v2.BatchCreateLogsRequest
40, // 41: coder.agent.v2.Agent.StreamDERPMaps:input_type -> coder.tailnet.v2.StreamDERPMapsRequest 10, // 41: coder.agent.v2.Agent.GetManifest:output_type -> coder.agent.v2.Manifest
41, // 42: coder.agent.v2.Agent.CoordinateTailnet:input_type -> coder.tailnet.v2.CoordinateRequest 12, // 42: coder.agent.v2.Agent.GetServiceBanner:output_type -> coder.agent.v2.ServiceBanner
10, // 43: coder.agent.v2.Agent.GetManifest:output_type -> coder.agent.v2.Manifest 16, // 43: coder.agent.v2.Agent.UpdateStats:output_type -> coder.agent.v2.UpdateStatsResponse
12, // 44: coder.agent.v2.Agent.GetServiceBanner:output_type -> coder.agent.v2.ServiceBanner 17, // 44: coder.agent.v2.Agent.UpdateLifecycle:output_type -> coder.agent.v2.Lifecycle
16, // 45: coder.agent.v2.Agent.UpdateStats:output_type -> coder.agent.v2.UpdateStatsResponse 20, // 45: coder.agent.v2.Agent.BatchUpdateAppHealths:output_type -> coder.agent.v2.BatchUpdateAppHealthResponse
17, // 46: coder.agent.v2.Agent.UpdateLifecycle:output_type -> coder.agent.v2.Lifecycle 21, // 46: coder.agent.v2.Agent.UpdateStartup:output_type -> coder.agent.v2.Startup
20, // 47: coder.agent.v2.Agent.BatchUpdateAppHealths:output_type -> coder.agent.v2.BatchUpdateAppHealthResponse 25, // 47: coder.agent.v2.Agent.BatchUpdateMetadata:output_type -> coder.agent.v2.BatchUpdateMetadataResponse
21, // 48: coder.agent.v2.Agent.UpdateStartup:output_type -> coder.agent.v2.Startup 28, // 48: coder.agent.v2.Agent.BatchCreateLogs:output_type -> coder.agent.v2.BatchCreateLogsResponse
25, // 49: coder.agent.v2.Agent.BatchUpdateMetadata:output_type -> coder.agent.v2.BatchUpdateMetadataResponse 41, // [41:49] is the sub-list for method output_type
28, // 50: coder.agent.v2.Agent.BatchCreateLogs:output_type -> coder.agent.v2.BatchCreateLogsResponse 33, // [33:41] is the sub-list for method input_type
38, // 51: coder.agent.v2.Agent.StreamDERPMaps:output_type -> coder.tailnet.v2.DERPMap
42, // 52: coder.agent.v2.Agent.CoordinateTailnet:output_type -> coder.tailnet.v2.CoordinateResponse
43, // [43:53] is the sub-list for method output_type
33, // [33:43] is the sub-list for method input_type
33, // [33:33] is the sub-list for extension type_name 33, // [33:33] is the sub-list for extension type_name
33, // [33:33] is the sub-list for extension extendee 33, // [33:33] is the sub-list for extension extendee
0, // [0:33] is the sub-list for field type_name 0, // [0:33] is the sub-list for field type_name

View File

@ -256,7 +256,4 @@ service Agent {
rpc UpdateStartup(UpdateStartupRequest) returns (Startup); rpc UpdateStartup(UpdateStartupRequest) returns (Startup);
rpc BatchUpdateMetadata(BatchUpdateMetadataRequest) returns (BatchUpdateMetadataResponse); rpc BatchUpdateMetadata(BatchUpdateMetadataRequest) returns (BatchUpdateMetadataResponse);
rpc BatchCreateLogs(BatchCreateLogsRequest) returns (BatchCreateLogsResponse); rpc BatchCreateLogs(BatchCreateLogsRequest) returns (BatchCreateLogsResponse);
rpc StreamDERPMaps(tailnet.v2.StreamDERPMapsRequest) returns (stream tailnet.v2.DERPMap);
rpc CoordinateTailnet(stream tailnet.v2.CoordinateRequest) returns (stream tailnet.v2.CoordinateResponse);
} }

View File

@ -7,7 +7,6 @@ package proto
import ( import (
context "context" context "context"
errors "errors" errors "errors"
proto1 "github.com/coder/coder/v2/tailnet/proto"
protojson "google.golang.org/protobuf/encoding/protojson" protojson "google.golang.org/protobuf/encoding/protojson"
proto "google.golang.org/protobuf/proto" proto "google.golang.org/protobuf/proto"
drpc "storj.io/drpc" drpc "storj.io/drpc"
@ -47,8 +46,6 @@ type DRPCAgentClient interface {
UpdateStartup(ctx context.Context, in *UpdateStartupRequest) (*Startup, error) UpdateStartup(ctx context.Context, in *UpdateStartupRequest) (*Startup, error)
BatchUpdateMetadata(ctx context.Context, in *BatchUpdateMetadataRequest) (*BatchUpdateMetadataResponse, error) BatchUpdateMetadata(ctx context.Context, in *BatchUpdateMetadataRequest) (*BatchUpdateMetadataResponse, error)
BatchCreateLogs(ctx context.Context, in *BatchCreateLogsRequest) (*BatchCreateLogsResponse, error) BatchCreateLogs(ctx context.Context, in *BatchCreateLogsRequest) (*BatchCreateLogsResponse, error)
StreamDERPMaps(ctx context.Context, in *proto1.StreamDERPMapsRequest) (DRPCAgent_StreamDERPMapsClient, error)
CoordinateTailnet(ctx context.Context) (DRPCAgent_CoordinateTailnetClient, error)
} }
type drpcAgentClient struct { type drpcAgentClient struct {
@ -133,85 +130,6 @@ func (c *drpcAgentClient) BatchCreateLogs(ctx context.Context, in *BatchCreateLo
return out, nil return out, nil
} }
func (c *drpcAgentClient) StreamDERPMaps(ctx context.Context, in *proto1.StreamDERPMapsRequest) (DRPCAgent_StreamDERPMapsClient, error) {
stream, err := c.cc.NewStream(ctx, "/coder.agent.v2.Agent/StreamDERPMaps", drpcEncoding_File_agent_proto_agent_proto{})
if err != nil {
return nil, err
}
x := &drpcAgent_StreamDERPMapsClient{stream}
if err := x.MsgSend(in, drpcEncoding_File_agent_proto_agent_proto{}); err != nil {
return nil, err
}
if err := x.CloseSend(); err != nil {
return nil, err
}
return x, nil
}
type DRPCAgent_StreamDERPMapsClient interface {
drpc.Stream
Recv() (*proto1.DERPMap, error)
}
type drpcAgent_StreamDERPMapsClient struct {
drpc.Stream
}
func (x *drpcAgent_StreamDERPMapsClient) GetStream() drpc.Stream {
return x.Stream
}
func (x *drpcAgent_StreamDERPMapsClient) Recv() (*proto1.DERPMap, error) {
m := new(proto1.DERPMap)
if err := x.MsgRecv(m, drpcEncoding_File_agent_proto_agent_proto{}); err != nil {
return nil, err
}
return m, nil
}
func (x *drpcAgent_StreamDERPMapsClient) RecvMsg(m *proto1.DERPMap) error {
return x.MsgRecv(m, drpcEncoding_File_agent_proto_agent_proto{})
}
func (c *drpcAgentClient) CoordinateTailnet(ctx context.Context) (DRPCAgent_CoordinateTailnetClient, error) {
stream, err := c.cc.NewStream(ctx, "/coder.agent.v2.Agent/CoordinateTailnet", drpcEncoding_File_agent_proto_agent_proto{})
if err != nil {
return nil, err
}
x := &drpcAgent_CoordinateTailnetClient{stream}
return x, nil
}
type DRPCAgent_CoordinateTailnetClient interface {
drpc.Stream
Send(*proto1.CoordinateRequest) error
Recv() (*proto1.CoordinateResponse, error)
}
type drpcAgent_CoordinateTailnetClient struct {
drpc.Stream
}
func (x *drpcAgent_CoordinateTailnetClient) GetStream() drpc.Stream {
return x.Stream
}
func (x *drpcAgent_CoordinateTailnetClient) Send(m *proto1.CoordinateRequest) error {
return x.MsgSend(m, drpcEncoding_File_agent_proto_agent_proto{})
}
func (x *drpcAgent_CoordinateTailnetClient) Recv() (*proto1.CoordinateResponse, error) {
m := new(proto1.CoordinateResponse)
if err := x.MsgRecv(m, drpcEncoding_File_agent_proto_agent_proto{}); err != nil {
return nil, err
}
return m, nil
}
func (x *drpcAgent_CoordinateTailnetClient) RecvMsg(m *proto1.CoordinateResponse) error {
return x.MsgRecv(m, drpcEncoding_File_agent_proto_agent_proto{})
}
type DRPCAgentServer interface { type DRPCAgentServer interface {
GetManifest(context.Context, *GetManifestRequest) (*Manifest, error) GetManifest(context.Context, *GetManifestRequest) (*Manifest, error)
GetServiceBanner(context.Context, *GetServiceBannerRequest) (*ServiceBanner, error) GetServiceBanner(context.Context, *GetServiceBannerRequest) (*ServiceBanner, error)
@ -221,8 +139,6 @@ type DRPCAgentServer interface {
UpdateStartup(context.Context, *UpdateStartupRequest) (*Startup, error) UpdateStartup(context.Context, *UpdateStartupRequest) (*Startup, error)
BatchUpdateMetadata(context.Context, *BatchUpdateMetadataRequest) (*BatchUpdateMetadataResponse, error) BatchUpdateMetadata(context.Context, *BatchUpdateMetadataRequest) (*BatchUpdateMetadataResponse, error)
BatchCreateLogs(context.Context, *BatchCreateLogsRequest) (*BatchCreateLogsResponse, error) BatchCreateLogs(context.Context, *BatchCreateLogsRequest) (*BatchCreateLogsResponse, error)
StreamDERPMaps(*proto1.StreamDERPMapsRequest, DRPCAgent_StreamDERPMapsStream) error
CoordinateTailnet(DRPCAgent_CoordinateTailnetStream) error
} }
type DRPCAgentUnimplementedServer struct{} type DRPCAgentUnimplementedServer struct{}
@ -259,17 +175,9 @@ func (s *DRPCAgentUnimplementedServer) BatchCreateLogs(context.Context, *BatchCr
return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented) return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented)
} }
func (s *DRPCAgentUnimplementedServer) StreamDERPMaps(*proto1.StreamDERPMapsRequest, DRPCAgent_StreamDERPMapsStream) error {
return drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented)
}
func (s *DRPCAgentUnimplementedServer) CoordinateTailnet(DRPCAgent_CoordinateTailnetStream) error {
return drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented)
}
type DRPCAgentDescription struct{} type DRPCAgentDescription struct{}
func (DRPCAgentDescription) NumMethods() int { return 10 } func (DRPCAgentDescription) NumMethods() int { return 8 }
func (DRPCAgentDescription) Method(n int) (string, drpc.Encoding, drpc.Receiver, interface{}, bool) { func (DRPCAgentDescription) Method(n int) (string, drpc.Encoding, drpc.Receiver, interface{}, bool) {
switch n { switch n {
@ -345,23 +253,6 @@ func (DRPCAgentDescription) Method(n int) (string, drpc.Encoding, drpc.Receiver,
in1.(*BatchCreateLogsRequest), in1.(*BatchCreateLogsRequest),
) )
}, DRPCAgentServer.BatchCreateLogs, true }, DRPCAgentServer.BatchCreateLogs, true
case 8:
return "/coder.agent.v2.Agent/StreamDERPMaps", drpcEncoding_File_agent_proto_agent_proto{},
func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) {
return nil, srv.(DRPCAgentServer).
StreamDERPMaps(
in1.(*proto1.StreamDERPMapsRequest),
&drpcAgent_StreamDERPMapsStream{in2.(drpc.Stream)},
)
}, DRPCAgentServer.StreamDERPMaps, true
case 9:
return "/coder.agent.v2.Agent/CoordinateTailnet", drpcEncoding_File_agent_proto_agent_proto{},
func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) {
return nil, srv.(DRPCAgentServer).
CoordinateTailnet(
&drpcAgent_CoordinateTailnetStream{in1.(drpc.Stream)},
)
}, DRPCAgentServer.CoordinateTailnet, true
default: default:
return "", nil, nil, nil, false return "", nil, nil, nil, false
} }
@ -498,42 +389,3 @@ func (x *drpcAgent_BatchCreateLogsStream) SendAndClose(m *BatchCreateLogsRespons
} }
return x.CloseSend() return x.CloseSend()
} }
type DRPCAgent_StreamDERPMapsStream interface {
drpc.Stream
Send(*proto1.DERPMap) error
}
type drpcAgent_StreamDERPMapsStream struct {
drpc.Stream
}
func (x *drpcAgent_StreamDERPMapsStream) Send(m *proto1.DERPMap) error {
return x.MsgSend(m, drpcEncoding_File_agent_proto_agent_proto{})
}
type DRPCAgent_CoordinateTailnetStream interface {
drpc.Stream
Send(*proto1.CoordinateResponse) error
Recv() (*proto1.CoordinateRequest, error)
}
type drpcAgent_CoordinateTailnetStream struct {
drpc.Stream
}
func (x *drpcAgent_CoordinateTailnetStream) Send(m *proto1.CoordinateResponse) error {
return x.MsgSend(m, drpcEncoding_File_agent_proto_agent_proto{})
}
func (x *drpcAgent_CoordinateTailnetStream) Recv() (*proto1.CoordinateRequest, error) {
m := new(proto1.CoordinateRequest)
if err := x.MsgRecv(m, drpcEncoding_File_agent_proto_agent_proto{}); err != nil {
return nil, err
}
return m, nil
}
func (x *drpcAgent_CoordinateTailnetStream) RecvMsg(m *proto1.CoordinateRequest) error {
return x.MsgRecv(m, drpcEncoding_File_agent_proto_agent_proto{})
}

View File

@ -42,7 +42,6 @@ type API struct {
*AppsAPI *AppsAPI
*MetadataAPI *MetadataAPI
*LogsAPI *LogsAPI
*TailnetAPI
mu sync.Mutex mu sync.Mutex
cachedWorkspaceID uuid.UUID cachedWorkspaceID uuid.UUID
@ -146,12 +145,6 @@ func New(opts Options) *API {
PublishWorkspaceAgentLogsUpdateFn: opts.PublishWorkspaceAgentLogsUpdateFn, PublishWorkspaceAgentLogsUpdateFn: opts.PublishWorkspaceAgentLogsUpdateFn,
} }
api.TailnetAPI = &TailnetAPI{
Ctx: opts.Ctx,
DerpMapFn: opts.DerpMapFn,
DerpMapUpdateFrequency: opts.DerpMapUpdateFrequency,
}
return api return api
} }

View File

@ -1,53 +0,0 @@
package agentapi
import (
"context"
"time"
"golang.org/x/xerrors"
"tailscale.com/tailcfg"
agentproto "github.com/coder/coder/v2/agent/proto"
"github.com/coder/coder/v2/tailnet"
tailnetproto "github.com/coder/coder/v2/tailnet/proto"
)
type TailnetAPI struct {
Ctx context.Context
DerpMapFn func() *tailcfg.DERPMap
DerpMapUpdateFrequency time.Duration
}
func (a *TailnetAPI) StreamDERPMaps(_ *tailnetproto.StreamDERPMapsRequest, stream agentproto.DRPCAgent_StreamDERPMapsStream) error {
defer stream.Close()
ticker := time.NewTicker(a.DerpMapUpdateFrequency)
defer ticker.Stop()
var lastDERPMap *tailcfg.DERPMap
for {
derpMap := a.DerpMapFn()
if lastDERPMap == nil || !tailnet.CompareDERPMaps(lastDERPMap, derpMap) {
protoDERPMap := tailnet.DERPMapToProto(derpMap)
err := stream.Send(protoDERPMap)
if err != nil {
return xerrors.Errorf("send derp map: %w", err)
}
lastDERPMap = derpMap
}
ticker.Reset(a.DerpMapUpdateFrequency)
select {
case <-stream.Context().Done():
return nil
case <-a.Ctx.Done():
return nil
case <-ticker.C:
}
}
}
func (*TailnetAPI) CoordinateTailnet(_ agentproto.DRPCAgent_CoordinateTailnetStream) error {
// TODO: implement this
return xerrors.New("CoordinateTailnet is unimplemented")
}

View File

@ -11,12 +11,12 @@ import (
"github.com/coder/coder/v2/tailnet/proto" "github.com/coder/coder/v2/tailnet/proto"
) )
func NewDRPCClient(conn net.Conn) (proto.DRPCClientClient, error) { func NewDRPCClient(conn net.Conn) (proto.DRPCTailnetClient, error) {
config := yamux.DefaultConfig() config := yamux.DefaultConfig()
config.LogOutput = io.Discard config.LogOutput = io.Discard
session, err := yamux.Client(conn, config) session, err := yamux.Client(conn, config)
if err != nil { if err != nil {
return nil, xerrors.Errorf("multiplex client: %w", err) return nil, xerrors.Errorf("multiplex client: %w", err)
} }
return proto.NewDRPCClientClient(drpc.MultiplexedConn(session)), nil return proto.NewDRPCTailnetClient(drpc.MultiplexedConn(session)), nil
} }

View File

@ -1041,23 +1041,22 @@ var file_tailnet_proto_tailnet_proto_rawDesc = []byte{
0x14, 0x0a, 0x10, 0x4b, 0x49, 0x4e, 0x44, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x14, 0x0a, 0x10, 0x4b, 0x49, 0x4e, 0x44, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46,
0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x08, 0x0a, 0x04, 0x4e, 0x4f, 0x44, 0x45, 0x10, 0x01, 0x12, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x08, 0x0a, 0x04, 0x4e, 0x4f, 0x44, 0x45, 0x10, 0x01, 0x12,
0x10, 0x0a, 0x0c, 0x44, 0x49, 0x53, 0x43, 0x4f, 0x4e, 0x4e, 0x45, 0x43, 0x54, 0x45, 0x44, 0x10, 0x10, 0x0a, 0x0c, 0x44, 0x49, 0x53, 0x43, 0x4f, 0x4e, 0x4e, 0x45, 0x43, 0x54, 0x45, 0x44, 0x10,
0x02, 0x12, 0x08, 0x0a, 0x04, 0x4c, 0x4f, 0x53, 0x54, 0x10, 0x03, 0x32, 0xc4, 0x01, 0x0a, 0x06, 0x02, 0x12, 0x08, 0x0a, 0x04, 0x4c, 0x4f, 0x53, 0x54, 0x10, 0x03, 0x32, 0xbe, 0x01, 0x0a, 0x07,
0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x12, 0x56, 0x0a, 0x0e, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x54, 0x61, 0x69, 0x6c, 0x6e, 0x65, 0x74, 0x12, 0x56, 0x0a, 0x0e, 0x53, 0x74, 0x72, 0x65, 0x61,
0x44, 0x45, 0x52, 0x50, 0x4d, 0x61, 0x70, 0x73, 0x12, 0x27, 0x2e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x6d, 0x44, 0x45, 0x52, 0x50, 0x4d, 0x61, 0x70, 0x73, 0x12, 0x27, 0x2e, 0x63, 0x6f, 0x64, 0x65,
0x2e, 0x74, 0x61, 0x69, 0x6c, 0x6e, 0x65, 0x74, 0x2e, 0x76, 0x32, 0x2e, 0x53, 0x74, 0x72, 0x65, 0x72, 0x2e, 0x74, 0x61, 0x69, 0x6c, 0x6e, 0x65, 0x74, 0x2e, 0x76, 0x32, 0x2e, 0x53, 0x74, 0x72,
0x61, 0x6d, 0x44, 0x45, 0x52, 0x50, 0x4d, 0x61, 0x70, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x65, 0x61, 0x6d, 0x44, 0x45, 0x52, 0x50, 0x4d, 0x61, 0x70, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65,
0x74, 0x1a, 0x19, 0x2e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2e, 0x74, 0x61, 0x69, 0x6c, 0x6e, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2e, 0x74, 0x61, 0x69, 0x6c, 0x6e,
0x74, 0x2e, 0x76, 0x32, 0x2e, 0x44, 0x45, 0x52, 0x50, 0x4d, 0x61, 0x70, 0x30, 0x01, 0x12, 0x62, 0x65, 0x74, 0x2e, 0x76, 0x32, 0x2e, 0x44, 0x45, 0x52, 0x50, 0x4d, 0x61, 0x70, 0x30, 0x01, 0x12,
0x0a, 0x11, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x54, 0x61, 0x69, 0x6c, 0x5b, 0x0a, 0x0a, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x12, 0x23, 0x2e,
0x6e, 0x65, 0x74, 0x12, 0x23, 0x2e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2e, 0x74, 0x61, 0x69, 0x6c, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2e, 0x74, 0x61, 0x69, 0x6c, 0x6e, 0x65, 0x74, 0x2e, 0x76, 0x32,
0x6e, 0x65, 0x74, 0x2e, 0x76, 0x32, 0x2e, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x2e, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65,
0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x24, 0x2e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x73, 0x74, 0x1a, 0x24, 0x2e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2e, 0x74, 0x61, 0x69, 0x6c, 0x6e,
0x2e, 0x74, 0x61, 0x69, 0x6c, 0x6e, 0x65, 0x74, 0x2e, 0x76, 0x32, 0x2e, 0x43, 0x6f, 0x6f, 0x72, 0x65, 0x74, 0x2e, 0x76, 0x32, 0x2e, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65,
0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x28, 0x01, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x28, 0x01, 0x30, 0x01, 0x42, 0x29, 0x5a, 0x27,
0x30, 0x01, 0x42, 0x29, 0x5a, 0x27, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x64, 0x65, 0x72,
0x2f, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2f, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2f, 0x76, 0x32, 0x2f, 0x2f, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2f, 0x76, 0x32, 0x2f, 0x74, 0x61, 0x69, 0x6c, 0x6e, 0x65,
0x74, 0x61, 0x69, 0x6c, 0x6e, 0x65, 0x74, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x74, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x72, 0x6f, 0x74, 0x6f, 0x33,
} }
var ( var (
@ -1111,10 +1110,10 @@ var file_tailnet_proto_tailnet_proto_depIdxs = []int32{
3, // 13: coder.tailnet.v2.CoordinateRequest.UpdateSelf.node:type_name -> coder.tailnet.v2.Node 3, // 13: coder.tailnet.v2.CoordinateRequest.UpdateSelf.node:type_name -> coder.tailnet.v2.Node
3, // 14: coder.tailnet.v2.CoordinateResponse.PeerUpdate.node:type_name -> coder.tailnet.v2.Node 3, // 14: coder.tailnet.v2.CoordinateResponse.PeerUpdate.node:type_name -> coder.tailnet.v2.Node
0, // 15: coder.tailnet.v2.CoordinateResponse.PeerUpdate.kind:type_name -> coder.tailnet.v2.CoordinateResponse.PeerUpdate.Kind 0, // 15: coder.tailnet.v2.CoordinateResponse.PeerUpdate.kind:type_name -> coder.tailnet.v2.CoordinateResponse.PeerUpdate.Kind
2, // 16: coder.tailnet.v2.Client.StreamDERPMaps:input_type -> coder.tailnet.v2.StreamDERPMapsRequest 2, // 16: coder.tailnet.v2.Tailnet.StreamDERPMaps:input_type -> coder.tailnet.v2.StreamDERPMapsRequest
4, // 17: coder.tailnet.v2.Client.CoordinateTailnet:input_type -> coder.tailnet.v2.CoordinateRequest 4, // 17: coder.tailnet.v2.Tailnet.Coordinate:input_type -> coder.tailnet.v2.CoordinateRequest
1, // 18: coder.tailnet.v2.Client.StreamDERPMaps:output_type -> coder.tailnet.v2.DERPMap 1, // 18: coder.tailnet.v2.Tailnet.StreamDERPMaps:output_type -> coder.tailnet.v2.DERPMap
5, // 19: coder.tailnet.v2.Client.CoordinateTailnet:output_type -> coder.tailnet.v2.CoordinateResponse 5, // 19: coder.tailnet.v2.Tailnet.Coordinate:output_type -> coder.tailnet.v2.CoordinateResponse
18, // [18:20] is the sub-list for method output_type 18, // [18:20] is the sub-list for method output_type
16, // [16:18] is the sub-list for method input_type 16, // [16:18] is the sub-list for method input_type
16, // [16:16] is the sub-list for extension type_name 16, // [16:16] is the sub-list for extension type_name

View File

@ -88,7 +88,7 @@ message CoordinateResponse {
repeated PeerUpdate peer_updates = 1; repeated PeerUpdate peer_updates = 1;
} }
service Client { service Tailnet {
rpc StreamDERPMaps(StreamDERPMapsRequest) returns (stream DERPMap); rpc StreamDERPMaps(StreamDERPMapsRequest) returns (stream DERPMap);
rpc CoordinateTailnet(stream CoordinateRequest) returns (stream CoordinateResponse); rpc Coordinate(stream CoordinateRequest) returns (stream CoordinateResponse);
} }

View File

@ -35,29 +35,29 @@ func (drpcEncoding_File_tailnet_proto_tailnet_proto) JSONUnmarshal(buf []byte, m
return protojson.Unmarshal(buf, msg.(proto.Message)) return protojson.Unmarshal(buf, msg.(proto.Message))
} }
type DRPCClientClient interface { type DRPCTailnetClient interface {
DRPCConn() drpc.Conn DRPCConn() drpc.Conn
StreamDERPMaps(ctx context.Context, in *StreamDERPMapsRequest) (DRPCClient_StreamDERPMapsClient, error) StreamDERPMaps(ctx context.Context, in *StreamDERPMapsRequest) (DRPCTailnet_StreamDERPMapsClient, error)
CoordinateTailnet(ctx context.Context) (DRPCClient_CoordinateTailnetClient, error) Coordinate(ctx context.Context) (DRPCTailnet_CoordinateClient, error)
} }
type drpcClientClient struct { type drpcTailnetClient struct {
cc drpc.Conn cc drpc.Conn
} }
func NewDRPCClientClient(cc drpc.Conn) DRPCClientClient { func NewDRPCTailnetClient(cc drpc.Conn) DRPCTailnetClient {
return &drpcClientClient{cc} return &drpcTailnetClient{cc}
} }
func (c *drpcClientClient) DRPCConn() drpc.Conn { return c.cc } func (c *drpcTailnetClient) DRPCConn() drpc.Conn { return c.cc }
func (c *drpcClientClient) StreamDERPMaps(ctx context.Context, in *StreamDERPMapsRequest) (DRPCClient_StreamDERPMapsClient, error) { func (c *drpcTailnetClient) StreamDERPMaps(ctx context.Context, in *StreamDERPMapsRequest) (DRPCTailnet_StreamDERPMapsClient, error) {
stream, err := c.cc.NewStream(ctx, "/coder.tailnet.v2.Client/StreamDERPMaps", drpcEncoding_File_tailnet_proto_tailnet_proto{}) stream, err := c.cc.NewStream(ctx, "/coder.tailnet.v2.Tailnet/StreamDERPMaps", drpcEncoding_File_tailnet_proto_tailnet_proto{})
if err != nil { if err != nil {
return nil, err return nil, err
} }
x := &drpcClient_StreamDERPMapsClient{stream} x := &drpcTailnet_StreamDERPMapsClient{stream}
if err := x.MsgSend(in, drpcEncoding_File_tailnet_proto_tailnet_proto{}); err != nil { if err := x.MsgSend(in, drpcEncoding_File_tailnet_proto_tailnet_proto{}); err != nil {
return nil, err return nil, err
} }
@ -67,20 +67,20 @@ func (c *drpcClientClient) StreamDERPMaps(ctx context.Context, in *StreamDERPMap
return x, nil return x, nil
} }
type DRPCClient_StreamDERPMapsClient interface { type DRPCTailnet_StreamDERPMapsClient interface {
drpc.Stream drpc.Stream
Recv() (*DERPMap, error) Recv() (*DERPMap, error)
} }
type drpcClient_StreamDERPMapsClient struct { type drpcTailnet_StreamDERPMapsClient struct {
drpc.Stream drpc.Stream
} }
func (x *drpcClient_StreamDERPMapsClient) GetStream() drpc.Stream { func (x *drpcTailnet_StreamDERPMapsClient) GetStream() drpc.Stream {
return x.Stream return x.Stream
} }
func (x *drpcClient_StreamDERPMapsClient) Recv() (*DERPMap, error) { func (x *drpcTailnet_StreamDERPMapsClient) Recv() (*DERPMap, error) {
m := new(DERPMap) m := new(DERPMap)
if err := x.MsgRecv(m, drpcEncoding_File_tailnet_proto_tailnet_proto{}); err != nil { if err := x.MsgRecv(m, drpcEncoding_File_tailnet_proto_tailnet_proto{}); err != nil {
return nil, err return nil, err
@ -88,38 +88,38 @@ func (x *drpcClient_StreamDERPMapsClient) Recv() (*DERPMap, error) {
return m, nil return m, nil
} }
func (x *drpcClient_StreamDERPMapsClient) RecvMsg(m *DERPMap) error { func (x *drpcTailnet_StreamDERPMapsClient) RecvMsg(m *DERPMap) error {
return x.MsgRecv(m, drpcEncoding_File_tailnet_proto_tailnet_proto{}) return x.MsgRecv(m, drpcEncoding_File_tailnet_proto_tailnet_proto{})
} }
func (c *drpcClientClient) CoordinateTailnet(ctx context.Context) (DRPCClient_CoordinateTailnetClient, error) { func (c *drpcTailnetClient) Coordinate(ctx context.Context) (DRPCTailnet_CoordinateClient, error) {
stream, err := c.cc.NewStream(ctx, "/coder.tailnet.v2.Client/CoordinateTailnet", drpcEncoding_File_tailnet_proto_tailnet_proto{}) stream, err := c.cc.NewStream(ctx, "/coder.tailnet.v2.Tailnet/Coordinate", drpcEncoding_File_tailnet_proto_tailnet_proto{})
if err != nil { if err != nil {
return nil, err return nil, err
} }
x := &drpcClient_CoordinateTailnetClient{stream} x := &drpcTailnet_CoordinateClient{stream}
return x, nil return x, nil
} }
type DRPCClient_CoordinateTailnetClient interface { type DRPCTailnet_CoordinateClient interface {
drpc.Stream drpc.Stream
Send(*CoordinateRequest) error Send(*CoordinateRequest) error
Recv() (*CoordinateResponse, error) Recv() (*CoordinateResponse, error)
} }
type drpcClient_CoordinateTailnetClient struct { type drpcTailnet_CoordinateClient struct {
drpc.Stream drpc.Stream
} }
func (x *drpcClient_CoordinateTailnetClient) GetStream() drpc.Stream { func (x *drpcTailnet_CoordinateClient) GetStream() drpc.Stream {
return x.Stream return x.Stream
} }
func (x *drpcClient_CoordinateTailnetClient) Send(m *CoordinateRequest) error { func (x *drpcTailnet_CoordinateClient) Send(m *CoordinateRequest) error {
return x.MsgSend(m, drpcEncoding_File_tailnet_proto_tailnet_proto{}) return x.MsgSend(m, drpcEncoding_File_tailnet_proto_tailnet_proto{})
} }
func (x *drpcClient_CoordinateTailnetClient) Recv() (*CoordinateResponse, error) { func (x *drpcTailnet_CoordinateClient) Recv() (*CoordinateResponse, error) {
m := new(CoordinateResponse) m := new(CoordinateResponse)
if err := x.MsgRecv(m, drpcEncoding_File_tailnet_proto_tailnet_proto{}); err != nil { if err := x.MsgRecv(m, drpcEncoding_File_tailnet_proto_tailnet_proto{}); err != nil {
return nil, err return nil, err
@ -127,85 +127,85 @@ func (x *drpcClient_CoordinateTailnetClient) Recv() (*CoordinateResponse, error)
return m, nil return m, nil
} }
func (x *drpcClient_CoordinateTailnetClient) RecvMsg(m *CoordinateResponse) error { func (x *drpcTailnet_CoordinateClient) RecvMsg(m *CoordinateResponse) error {
return x.MsgRecv(m, drpcEncoding_File_tailnet_proto_tailnet_proto{}) return x.MsgRecv(m, drpcEncoding_File_tailnet_proto_tailnet_proto{})
} }
type DRPCClientServer interface { type DRPCTailnetServer interface {
StreamDERPMaps(*StreamDERPMapsRequest, DRPCClient_StreamDERPMapsStream) error StreamDERPMaps(*StreamDERPMapsRequest, DRPCTailnet_StreamDERPMapsStream) error
CoordinateTailnet(DRPCClient_CoordinateTailnetStream) error Coordinate(DRPCTailnet_CoordinateStream) error
} }
type DRPCClientUnimplementedServer struct{} type DRPCTailnetUnimplementedServer struct{}
func (s *DRPCClientUnimplementedServer) StreamDERPMaps(*StreamDERPMapsRequest, DRPCClient_StreamDERPMapsStream) error { func (s *DRPCTailnetUnimplementedServer) StreamDERPMaps(*StreamDERPMapsRequest, DRPCTailnet_StreamDERPMapsStream) error {
return drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented) return drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented)
} }
func (s *DRPCClientUnimplementedServer) CoordinateTailnet(DRPCClient_CoordinateTailnetStream) error { func (s *DRPCTailnetUnimplementedServer) Coordinate(DRPCTailnet_CoordinateStream) error {
return drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented) return drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented)
} }
type DRPCClientDescription struct{} type DRPCTailnetDescription struct{}
func (DRPCClientDescription) NumMethods() int { return 2 } func (DRPCTailnetDescription) NumMethods() int { return 2 }
func (DRPCClientDescription) Method(n int) (string, drpc.Encoding, drpc.Receiver, interface{}, bool) { func (DRPCTailnetDescription) Method(n int) (string, drpc.Encoding, drpc.Receiver, interface{}, bool) {
switch n { switch n {
case 0: case 0:
return "/coder.tailnet.v2.Client/StreamDERPMaps", drpcEncoding_File_tailnet_proto_tailnet_proto{}, return "/coder.tailnet.v2.Tailnet/StreamDERPMaps", drpcEncoding_File_tailnet_proto_tailnet_proto{},
func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) { func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) {
return nil, srv.(DRPCClientServer). return nil, srv.(DRPCTailnetServer).
StreamDERPMaps( StreamDERPMaps(
in1.(*StreamDERPMapsRequest), in1.(*StreamDERPMapsRequest),
&drpcClient_StreamDERPMapsStream{in2.(drpc.Stream)}, &drpcTailnet_StreamDERPMapsStream{in2.(drpc.Stream)},
) )
}, DRPCClientServer.StreamDERPMaps, true }, DRPCTailnetServer.StreamDERPMaps, true
case 1: case 1:
return "/coder.tailnet.v2.Client/CoordinateTailnet", drpcEncoding_File_tailnet_proto_tailnet_proto{}, return "/coder.tailnet.v2.Tailnet/Coordinate", drpcEncoding_File_tailnet_proto_tailnet_proto{},
func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) { func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) {
return nil, srv.(DRPCClientServer). return nil, srv.(DRPCTailnetServer).
CoordinateTailnet( Coordinate(
&drpcClient_CoordinateTailnetStream{in1.(drpc.Stream)}, &drpcTailnet_CoordinateStream{in1.(drpc.Stream)},
) )
}, DRPCClientServer.CoordinateTailnet, true }, DRPCTailnetServer.Coordinate, true
default: default:
return "", nil, nil, nil, false return "", nil, nil, nil, false
} }
} }
func DRPCRegisterClient(mux drpc.Mux, impl DRPCClientServer) error { func DRPCRegisterTailnet(mux drpc.Mux, impl DRPCTailnetServer) error {
return mux.Register(impl, DRPCClientDescription{}) return mux.Register(impl, DRPCTailnetDescription{})
} }
type DRPCClient_StreamDERPMapsStream interface { type DRPCTailnet_StreamDERPMapsStream interface {
drpc.Stream drpc.Stream
Send(*DERPMap) error Send(*DERPMap) error
} }
type drpcClient_StreamDERPMapsStream struct { type drpcTailnet_StreamDERPMapsStream struct {
drpc.Stream drpc.Stream
} }
func (x *drpcClient_StreamDERPMapsStream) Send(m *DERPMap) error { func (x *drpcTailnet_StreamDERPMapsStream) Send(m *DERPMap) error {
return x.MsgSend(m, drpcEncoding_File_tailnet_proto_tailnet_proto{}) return x.MsgSend(m, drpcEncoding_File_tailnet_proto_tailnet_proto{})
} }
type DRPCClient_CoordinateTailnetStream interface { type DRPCTailnet_CoordinateStream interface {
drpc.Stream drpc.Stream
Send(*CoordinateResponse) error Send(*CoordinateResponse) error
Recv() (*CoordinateRequest, error) Recv() (*CoordinateRequest, error)
} }
type drpcClient_CoordinateTailnetStream struct { type drpcTailnet_CoordinateStream struct {
drpc.Stream drpc.Stream
} }
func (x *drpcClient_CoordinateTailnetStream) Send(m *CoordinateResponse) error { func (x *drpcTailnet_CoordinateStream) Send(m *CoordinateResponse) error {
return x.MsgSend(m, drpcEncoding_File_tailnet_proto_tailnet_proto{}) return x.MsgSend(m, drpcEncoding_File_tailnet_proto_tailnet_proto{})
} }
func (x *drpcClient_CoordinateTailnetStream) Recv() (*CoordinateRequest, error) { func (x *drpcTailnet_CoordinateStream) Recv() (*CoordinateRequest, error) {
m := new(CoordinateRequest) m := new(CoordinateRequest)
if err := x.MsgRecv(m, drpcEncoding_File_tailnet_proto_tailnet_proto{}); err != nil { if err := x.MsgRecv(m, drpcEncoding_File_tailnet_proto_tailnet_proto{}); err != nil {
return nil, err return nil, err
@ -213,6 +213,6 @@ func (x *drpcClient_CoordinateTailnetStream) Recv() (*CoordinateRequest, error)
return m, nil return m, nil
} }
func (x *drpcClient_CoordinateTailnetStream) RecvMsg(m *CoordinateRequest) error { func (x *drpcTailnet_CoordinateStream) RecvMsg(m *CoordinateRequest) error {
return x.MsgRecv(m, drpcEncoding_File_tailnet_proto_tailnet_proto{}) return x.MsgRecv(m, drpcEncoding_File_tailnet_proto_tailnet_proto{})
} }

View File

@ -110,7 +110,7 @@ func NewClientService(
DerpMapUpdateFrequency: derpMapUpdateFrequency, DerpMapUpdateFrequency: derpMapUpdateFrequency,
DerpMapFn: derpMapFn, DerpMapFn: derpMapFn,
} }
err := proto.DRPCRegisterClient(mux, drpcService) err := proto.DRPCRegisterTailnet(mux, drpcService)
if err != nil { if err != nil {
return nil, xerrors.Errorf("register DRPC service: %w", err) return nil, xerrors.Errorf("register DRPC service: %w", err)
} }
@ -165,7 +165,7 @@ type DRPCService struct {
DerpMapFn func() *tailcfg.DERPMap DerpMapFn func() *tailcfg.DERPMap
} }
func (s *DRPCService) StreamDERPMaps(_ *proto.StreamDERPMapsRequest, stream proto.DRPCClient_StreamDERPMapsStream) error { func (s *DRPCService) StreamDERPMaps(_ *proto.StreamDERPMapsRequest, stream proto.DRPCTailnet_StreamDERPMapsStream) error {
defer stream.Close() defer stream.Close()
ticker := time.NewTicker(s.DerpMapUpdateFrequency) ticker := time.NewTicker(s.DerpMapUpdateFrequency)
@ -192,7 +192,7 @@ func (s *DRPCService) StreamDERPMaps(_ *proto.StreamDERPMapsRequest, stream prot
} }
} }
func (s *DRPCService) CoordinateTailnet(stream proto.DRPCClient_CoordinateTailnetStream) error { func (s *DRPCService) Coordinate(stream proto.DRPCTailnet_CoordinateStream) error {
ctx := stream.Context() ctx := stream.Context()
streamID, ok := ctx.Value(streamIDContextKey{}).(StreamID) streamID, ok := ctx.Value(streamIDContextKey{}).(StreamID)
if !ok { if !ok {
@ -215,7 +215,7 @@ func (s *DRPCService) CoordinateTailnet(stream proto.DRPCClient_CoordinateTailne
type communicator struct { type communicator struct {
logger slog.Logger logger slog.Logger
stream proto.DRPCClient_CoordinateTailnetStream stream proto.DRPCTailnet_CoordinateStream
reqs chan<- *proto.CoordinateRequest reqs chan<- *proto.CoordinateRequest
resps <-chan *proto.CoordinateResponse resps <-chan *proto.CoordinateResponse
} }

View File

@ -120,7 +120,7 @@ func TestClientService_ServeClient_V2(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
// Coordinate // Coordinate
stream, err := client.CoordinateTailnet(ctx) stream, err := client.Coordinate(ctx)
require.NoError(t, err) require.NoError(t, err)
defer stream.Close() defer stream.Close()