Documentation ¶
Index ¶
Constants ¶
View Source
const DefaultReadBufSize int = 4096 // 默认交换数据缓冲大小
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type D2D ¶
type D2D struct { TryConnTime time.Duration // 尝试或发起连接时间,可能一方不在线,会一直尝试连接对方。(默认:1s) ReadBufSize int // 交换数据缓冲大小 Timeout time.Duration // 发起连接超时 ErrorLog *log.Logger // 日志 Context context.Context // 上下文 // contains filtered or unexported fields }
D2D 内网开放端口,外网无法访问的情况下。内网使用D2D主动连接外网端口。以便外网发来数据转发到内网端口中去。
------------------------------------- | | ←1 | | 2→ | |(1,A和B收到[D2D]发来连接) |A内网| ←4 |D2D| ←3 |B外网|(2,B然后向[D2D]回应数据,数据将转发到A内网。) | | 5→ | | 6→ | |(3,A内网收到数据再发出数据,由[D2D]转发到B外网。) -------------------------------------
type D2DSwap ¶
type D2DSwap struct { Verify func(a, b net.Conn) (net.Conn, net.Conn, error) // 数据交换前对双方连接操作,可以现实验证之类 // contains filtered or unexported fields }
D2DSwap 数据交换
type L2D ¶
type L2D struct { ReadBufSize int // 交换数据缓冲大小 Timeout time.Duration // TCP发起连接超时,udp远程读取超时(默认:60s) ErrorLog *log.Logger // 日志 Context context.Context // contains filtered or unexported fields }
L2D 是在内网或公网都可以使用,配合D2D或L2L使用功能更自由。L2D功能主要是转发连接(端口转发)。
------------------------------------- | | 1→ | | 2→ | |(1,B收到A发来数据) |A端口| ←4 |L2D| ←3 |B端口|(2,然后向A回应数据) | | 5→ | | 6→ | |(3,B然后再收到A数据) -------------------------------------
type L2DSwap ¶
type L2DSwap struct { Verify func(lconn, rconn net.Conn) (net.Conn, net.Conn, error) // 数据交换前对双方连接操作,可以现实验证之类 // contains filtered or unexported fields }
L2DSwap 数据交换
type L2L ¶
type L2L struct { ReadBufSize int // 交换数据缓冲大小 ErrorLog *log.Logger // 日志 // contains filtered or unexported fields }
L2L 是在公网主机上面监听两个TCP端口,由两个内网客户端连接。 L2L使这两个连接进行交换数据,达成内网到内网通道。 注意:1)双方必须主动连接公网L2L。2)不支持UDP协议。
------------------------------------ | | → | | ← | |(1,A和B同时连接[D2D],由[D2D]互相桥接A和B这两个连接) |A内网| ← |D2D| ← |B内网|(2,B 往 A 发送数据) | | → | | → | |(3,A 往 B 发送数据) ------------------------------------
Click to show internal directories.
Click to hide internal directories.