mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add port-forward subcommand (#1350)
This commit is contained in:
+2
-2
@@ -53,8 +53,8 @@ type ChannelOptions struct {
|
||||
// Arbitrary string that can be parsed on `Accept`.
|
||||
Protocol string
|
||||
|
||||
// Ordered determines whether the channel acts like
|
||||
// a TCP connection. Defaults to false.
|
||||
// Unordered determines whether the channel acts like
|
||||
// a UDP connection. Defaults to false.
|
||||
Unordered bool
|
||||
|
||||
// Whether the channel will be left open on disconnect or not.
|
||||
|
||||
+10
-9
@@ -68,7 +68,7 @@ func newWithClientOrServer(servers []webrtc.ICEServer, client bool, opts *ConnOp
|
||||
closed: make(chan struct{}),
|
||||
closedRTC: make(chan struct{}),
|
||||
closedICE: make(chan struct{}),
|
||||
dcOpenChannel: make(chan *webrtc.DataChannel),
|
||||
dcOpenChannel: make(chan *webrtc.DataChannel, 8),
|
||||
dcDisconnectChannel: make(chan struct{}),
|
||||
dcFailedChannel: make(chan struct{}),
|
||||
localCandidateChannel: make(chan webrtc.ICECandidateInit),
|
||||
@@ -264,12 +264,13 @@ func (c *Conn) init() error {
|
||||
}()
|
||||
})
|
||||
c.rtc.OnDataChannel(func(dc *webrtc.DataChannel) {
|
||||
select {
|
||||
case <-c.closed:
|
||||
return
|
||||
case c.dcOpenChannel <- dc:
|
||||
default:
|
||||
}
|
||||
go func() {
|
||||
select {
|
||||
case <-c.closed:
|
||||
return
|
||||
case c.dcOpenChannel <- dc:
|
||||
}
|
||||
}()
|
||||
})
|
||||
_, err := c.pingChannel()
|
||||
if err != nil {
|
||||
@@ -469,8 +470,8 @@ func (c *Conn) Accept(ctx context.Context) (*Channel, error) {
|
||||
return newChannel(c, dataChannel, &ChannelOptions{}), nil
|
||||
}
|
||||
|
||||
// Dial creates a new DataChannel.
|
||||
func (c *Conn) Dial(ctx context.Context, label string, opts *ChannelOptions) (*Channel, error) {
|
||||
// CreateChannel creates a new DataChannel.
|
||||
func (c *Conn) CreateChannel(ctx context.Context, label string, opts *ChannelOptions) (*Channel, error) {
|
||||
if opts == nil {
|
||||
opts = &ChannelOptions{}
|
||||
}
|
||||
|
||||
+7
-7
@@ -90,7 +90,7 @@ func TestConn(t *testing.T) {
|
||||
_, err := server.Ping()
|
||||
require.NoError(t, err)
|
||||
// Create a channel that closes on disconnect.
|
||||
channel, err := server.Dial(context.Background(), "wow", nil)
|
||||
channel, err := server.CreateChannel(context.Background(), "wow", nil)
|
||||
assert.NoError(t, err)
|
||||
err = wan.Stop()
|
||||
require.NoError(t, err)
|
||||
@@ -108,7 +108,7 @@ func TestConn(t *testing.T) {
|
||||
t.Parallel()
|
||||
client, server, _ := createPair(t)
|
||||
exchange(t, client, server)
|
||||
cch, err := client.Dial(context.Background(), "hello", &peer.ChannelOptions{})
|
||||
cch, err := client.CreateChannel(context.Background(), "hello", &peer.ChannelOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
sch, err := server.Accept(context.Background())
|
||||
@@ -124,7 +124,7 @@ func TestConn(t *testing.T) {
|
||||
t.Parallel()
|
||||
client, server, wan := createPair(t)
|
||||
exchange(t, client, server)
|
||||
cch, err := client.Dial(context.Background(), "hello", &peer.ChannelOptions{})
|
||||
cch, err := client.CreateChannel(context.Background(), "hello", &peer.ChannelOptions{})
|
||||
require.NoError(t, err)
|
||||
sch, err := server.Accept(context.Background())
|
||||
require.NoError(t, err)
|
||||
@@ -141,7 +141,7 @@ func TestConn(t *testing.T) {
|
||||
t.Parallel()
|
||||
client, server, _ := createPair(t)
|
||||
exchange(t, client, server)
|
||||
cch, err := client.Dial(context.Background(), "hello", &peer.ChannelOptions{})
|
||||
cch, err := client.CreateChannel(context.Background(), "hello", &peer.ChannelOptions{})
|
||||
require.NoError(t, err)
|
||||
sch, err := server.Accept(context.Background())
|
||||
require.NoError(t, err)
|
||||
@@ -196,7 +196,7 @@ func TestConn(t *testing.T) {
|
||||
defaultTransport := http.DefaultTransport.(*http.Transport).Clone()
|
||||
var cch *peer.Channel
|
||||
defaultTransport.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||
cch, err = client.Dial(ctx, "hello", &peer.ChannelOptions{})
|
||||
cch, err = client.CreateChannel(ctx, "hello", &peer.ChannelOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -234,7 +234,7 @@ func TestConn(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
expectedErr := xerrors.New("wow")
|
||||
_ = conn.CloseWithError(expectedErr)
|
||||
_, err = conn.Dial(context.Background(), "", nil)
|
||||
_, err = conn.CreateChannel(context.Background(), "", nil)
|
||||
require.ErrorIs(t, err, expectedErr)
|
||||
})
|
||||
|
||||
@@ -274,7 +274,7 @@ func TestConn(t *testing.T) {
|
||||
client, server, _ := createPair(t)
|
||||
exchange(t, client, server)
|
||||
go func() {
|
||||
channel, err := client.Dial(context.Background(), "test", nil)
|
||||
channel, err := client.CreateChannel(context.Background(), "test", nil)
|
||||
require.NoError(t, err)
|
||||
_, err = channel.Write([]byte{1, 2})
|
||||
require.NoError(t, err)
|
||||
|
||||
Reference in New Issue
Block a user