link

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2023 License: GPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LINK_STATUS_DOWN = iota
	LINK_STATUS_HALFUP
	LINK_STATUS_UP
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Link struct {
	// contains filtered or unexported fields
}

Link 是本机到 peer 的连接抽象

func (*Link) Accept

func (l *Link) Accept(ip net.IP) bool

Accept 判断是否应当接受 ip 发来的包

func (*Link) Close

func (l *Link) Close()

Close 关闭到 peer 的连接

func (*Link) Decode

func (l *Link) Decode(teatype uint8, b []byte) (db []byte)

Decode 使用 TEA 解密

func (*Link) DecodePreshared added in v0.9.4

func (l *Link) DecodePreshared(additional uint16, b []byte) (db []byte)

DecodePreshared 使用 xchacha20poly1305 解密

func (*Link) Destroy

func (l *Link) Destroy()

Destroy 从 connections 移除 peer

func (*Link) Encode

func (l *Link) Encode(teatype uint8, b []byte) (eb []byte)

Encode 使用 TEA 加密

func (*Link) EncodePreshared added in v0.9.4

func (l *Link) EncodePreshared(additional uint16, b []byte) (eb []byte)

EncodePreshared 使用 xchacha20poly1305 加密

func (*Link) IsToMe

func (l *Link) IsToMe(ip net.IP) bool

IsToMe 判断是否是发给自己的包

func (*Link) Read

func (l *Link) Read() *head.Packet

Read 从 peer 收包

func (*Link) String

func (l *Link) String() (n string)

func (*Link) WriteAndPut

func (l *Link) WriteAndPut(p *head.Packet, istransfer bool) (n int, err error)

WriteAndPut 向 peer 发包并将包放回缓存池

type Me

type Me struct {
	// contains filtered or unexported fields
}

Me 是本机的抽象

func NewMe

func NewMe(cfg *MyConfig) (m Me)

NewMe 设置本机参数

func (*Me) AddPeer

func (m *Me) AddPeer(cfg *PeerConfig) (l *Link)

AddPeer 添加一个 peer

func (*Me) Close

func (m *Me) Close() error

func (*Me) Connect

func (m *Me) Connect(peer string) (*Link, error)

Connect 初始化与 peer 的连接

func (*Me) DstPort

func (m *Me) DstPort() uint16

func (*Me) IsInPeer

func (m *Me) IsInPeer(peer string) (p *Link, ok bool)

IsInPeer 查找 peer 是否已经在册

func (*Me) ListenFromNIC

func (m *Me) ListenFromNIC() (written int64, err error)

func (*Me) MTU

func (m *Me) MTU() uint16

func (*Me) SrcPort

func (m *Me) SrcPort() uint16

func (*Me) Write

func (m *Me) Write(packet []byte) (n int, err error)

type MyConfig

type MyConfig struct {
	MyIPwithMask          string
	MyEndpoint            string
	PrivateKey            *[32]byte
	NIC                   lower.NICIO
	SrcPort, DstPort, MTU uint16
	Mask                  uint64
}

type PeerConfig

type PeerConfig struct {
	PeerIP                  string
	EndPoint                string
	AllowedIPs, Querys      []string
	PubicKey                *[32]byte
	PresharedKey            *[32]byte
	KeepAliveDur, QueryTick int64
	MTU                     uint16
	MTURandomRange          uint16
	AllowTrans, NoPipe      bool
	UseZstd                 bool
}

type Router

type Router struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*Router) NextHop

func (r *Router) NextHop(ip string) (l *Link)

NextHop 得到前往 ip 的下一跳的 link

func (*Router) SetDefault

func (r *Router) SetDefault(l *Link)

SetDefault 设置默认网关

func (*Router) SetItem

func (r *Router) SetItem(ip *net.IPNet, l *Link)

SetItem 添加一条表项

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL