mirror of
https://github.com/fumiama/WireGold.git
synced 2026-06-28 06:40:26 +08:00
fix mtu error
This commit is contained in:
@@ -1,73 +1,11 @@
|
||||
package link
|
||||
|
||||
import (
|
||||
"net"
|
||||
"sync"
|
||||
"unsafe"
|
||||
|
||||
tea "github.com/fumiama/gofastTEA"
|
||||
|
||||
"github.com/fumiama/WireGold/gold/head"
|
||||
)
|
||||
|
||||
// Me 是本机的抽象
|
||||
type Me struct {
|
||||
// 本机私钥
|
||||
// 利用 Curve25519 生成
|
||||
// https://pkg.go.dev/golang.org/x/crypto/curve25519
|
||||
// https://www.zhihu.com/question/266758647
|
||||
privKey [32]byte
|
||||
// 本机虚拟 ip
|
||||
me net.IP
|
||||
// 本机子网
|
||||
subnet net.IPNet
|
||||
// 本机 endpoint
|
||||
myend *net.UDPAddr
|
||||
// 本机环回 link
|
||||
loop *Link
|
||||
// 本机活跃的所有连接
|
||||
connections map[string]*Link
|
||||
// 读写同步锁
|
||||
connmapmu sync.RWMutex
|
||||
// 本机监听的 endpoint
|
||||
myconn *net.UDPConn
|
||||
// 不分目的 link 的接收队列
|
||||
pipe chan *head.Packet
|
||||
// 本机路由表
|
||||
router *Router
|
||||
}
|
||||
|
||||
// NewMe 设置本机参数
|
||||
func NewMe(privateKey *[32]byte, myipwithmask string, myEndpoint string, nopipeinlink bool) (m Me) {
|
||||
m.privKey = *privateKey
|
||||
var err error
|
||||
m.myend, err = net.ResolveUDPAddr("udp", myEndpoint)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
ip, cidr, err := net.ParseCIDR(myipwithmask)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
m.me = ip
|
||||
m.subnet = *cidr
|
||||
m.myconn, err = m.listen()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
m.connections = make(map[string]*Link)
|
||||
if nopipeinlink {
|
||||
m.pipe = make(chan *head.Packet, 32)
|
||||
}
|
||||
m.router = &Router{
|
||||
list: make([]*net.IPNet, 1, 16),
|
||||
table: make(map[string]*Link, 16),
|
||||
}
|
||||
m.router.SetDefault(nil)
|
||||
m.loop = m.AddPeer(m.me.String(), nil, "127.0.0.1:56789", []string{myipwithmask}, 0, false, nopipeinlink)
|
||||
return
|
||||
}
|
||||
|
||||
// Encode 使用 TEA 加密
|
||||
func (l *Link) Encode(b []byte) (eb []byte) {
|
||||
if b == nil {
|
||||
|
||||
Reference in New Issue
Block a user