mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
Part of #10532 Adds a tailnet ClientService that accepts a net.Conn and serves v1 or v2 of the tailnet API. Also adds a DRPCService that implements the DRPC interface for the v2 API. This component is within the ClientService, but needs to be reusable and exported so that we can also embed it in the Agent API. Finally, includes a NewDRPCClient function that takes a net.Conn and runs dRPC in yamux over it on the client side.
23 lines
510 B
Go
23 lines
510 B
Go
package tailnet
|
|
|
|
import (
|
|
"io"
|
|
"net"
|
|
|
|
"github.com/hashicorp/yamux"
|
|
"golang.org/x/xerrors"
|
|
|
|
"github.com/coder/coder/v2/codersdk/drpc"
|
|
"github.com/coder/coder/v2/tailnet/proto"
|
|
)
|
|
|
|
func NewDRPCClient(conn net.Conn) (proto.DRPCClientClient, error) {
|
|
config := yamux.DefaultConfig()
|
|
config.LogOutput = io.Discard
|
|
session, err := yamux.Client(conn, config)
|
|
if err != nil {
|
|
return nil, xerrors.Errorf("multiplex client: %w", err)
|
|
}
|
|
return proto.NewDRPCClientClient(drpc.MultiplexedConn(session)), nil
|
|
}
|