Documentation ¶
Overview ¶
Tcp connection builder
Bind to a port, connect to a rendezvous server. Wait for peer connection request or initiate a peer connection request.
Example (Client1) ¶
c := tcp.NewClient(rndzServer, "c1", netip.AddrPort{}) defer c.Close() l, _ := c.Listen(context.Background()) defer l.Close() for { conn, _ := l.Accept() defer conn.Close() // ... }
Output:
Example (Client2) ¶
c := tcp.NewClient(rndzServer, "c2", netip.AddrPort{}) defer c.Close() conn, _ := c.Connect(context.Background(), "c1") defer conn.Close()
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Tcp connection builder
func New ¶
set rendezvous server, peer identity, local bind address. if no local address set, choose according server address type(ipv4 or ipv6).
func (*Client) Connect ¶
connect to rendezvous server and request a connection to target node.
it will return a net.Conn with remote peer.
the connection with rendezvous server will be drop after return.
func (*Client) Listen ¶
put socket in listen mode, create connection with rendezvous server, wait for peer connection request. if connection with server broken it will auto reconnect.
when received `Fsync` request from server, attempt to connect remote peer with a very short timeout, this will open the firwall and nat rule for the peer connection that will follow immediately. When the peer connection finally come, the listening socket then accept it as normal.