relay: added private tunnel

This commit is contained in:
ginuerzh
2023-01-29 11:55:26 +08:00
parent 93b40f4c86
commit 24037aba7b
11 changed files with 174 additions and 59 deletions

View File

@ -48,7 +48,7 @@ func (c *relayConnector) tunnel(ctx context.Context, conn net.Conn, log logger.L
if err != nil {
return nil, err
}
log.Debugf("create tunnel %s connector %s OK", c.md.tunnelID, cid)
log.Debugf("create tunnel %s connector %s OK", c.md.tunnelID.String(), cid)
session, err := mux.ServerSession(conn)
if err != nil {
@ -90,7 +90,7 @@ func (c *relayConnector) initTunnel(conn net.Conn) (addr net.Addr, cid relay.Con
}
if resp.Status != relay.StatusOK {
err = fmt.Errorf("%d: create tunnel %s failed", resp.Status, c.md.tunnelID)
err = fmt.Errorf("%d: create tunnel %s failed", resp.Status, c.md.tunnelID.String())
return
}

View File

@ -83,11 +83,13 @@ func (c *relayConnector) Connect(ctx context.Context, conn net.Conn, network, ad
if err := af.ParseFrom(address); err != nil {
return nil, err
}
req.Features = append(req.Features, af)
}
// forward mode if port is 0.
if af.Port > 0 {
req.Features = append(req.Features, af)
}
if !c.md.tunnelID.IsZero() {
req.Features = append(req.Features, &relay.TunnelFeature{
ID: c.md.tunnelID,
})
}
if c.md.noDelay {

View File

@ -30,7 +30,7 @@ func (c *relayConnector) parseMetadata(md mdata.Metadata) (err error) {
if err != nil {
return err
}
copy(c.md.tunnelID[:], uuid[:])
c.md.tunnelID = relay.NewTunnelID(uuid[:])
}
return