mirror of
https://github.com/fumiama/WireGold.git
synced 2026-06-09 02:02:41 +08:00
优化封装
This commit is contained in:
@@ -27,9 +27,9 @@ func TestTunnel(t *testing.T) {
|
||||
t.Log("peer priv key:", hex.EncodeToString(peerpk.Private()[:]))
|
||||
t.Log("peer publ key:", hex.EncodeToString(peerpk.Public()[:]))
|
||||
|
||||
m := link.NewMe(selfpk.Private(), "192.168.1.2/32", "127.0.0.1:1236", false, 1, 1, 4096)
|
||||
m := link.NewMe(selfpk.Private(), "192.168.1.2/32", "127.0.0.1:1236", nil, 1, 1, 4096)
|
||||
m.AddPeer("192.168.1.3", peerpk.Public(), "127.0.0.1:1237", []string{"192.168.1.3/32"}, 0, false, false)
|
||||
p := link.NewMe(peerpk.Private(), "192.168.1.3/32", "127.0.0.1:1237", false, 1, 1, 4096)
|
||||
p := link.NewMe(peerpk.Private(), "192.168.1.3/32", "127.0.0.1:1237", nil, 1, 1, 4096)
|
||||
p.AddPeer("192.168.1.2", selfpk.Public(), "127.0.0.1:1236", []string{"192.168.1.2/32"}, 0, false, false)
|
||||
tunnme, err := Create(&m, "192.168.1.3")
|
||||
if err != nil {
|
||||
|
||||
@@ -19,7 +19,7 @@ type WG struct {
|
||||
c *config.Config
|
||||
key [32]byte
|
||||
PublicKey string
|
||||
nic *lower.NIC
|
||||
nic lower.NICIO
|
||||
me link.Me
|
||||
}
|
||||
|
||||
@@ -50,19 +50,18 @@ func NewWireGold(c *config.Config) (wg WG, err error) {
|
||||
func (wg *WG) Start(srcport, destport, mtu uint16) {
|
||||
wg.init(srcport, destport, mtu)
|
||||
wg.nic.Up()
|
||||
go wg.nic.Start(&wg.me)
|
||||
go wg.me.ListenFromNIC()
|
||||
}
|
||||
|
||||
func (wg *WG) Run(srcport, destport, mtu uint16) {
|
||||
wg.init(srcport, destport, mtu)
|
||||
wg.nic.Up()
|
||||
wg.nic.Start(&wg.me)
|
||||
wg.me.ListenFromNIC()
|
||||
}
|
||||
|
||||
func (wg *WG) Stop() {
|
||||
wg.nic.Stop()
|
||||
wg.nic.Close()
|
||||
wg.nic.Down()
|
||||
wg.nic.Destroy()
|
||||
}
|
||||
|
||||
func (wg *WG) init(srcport, destport, mtu uint16) {
|
||||
@@ -89,8 +88,13 @@ func (wg *WG) init(srcport, destport, mtu uint16) {
|
||||
i++
|
||||
}
|
||||
|
||||
wg.nic = lower.NewNIC(wg.c.IP, wg.c.SubNet, cidrs...)
|
||||
wg.me = link.NewMe(&wg.key, wg.c.IP+"/32", wg.c.EndPoint, true, srcport, destport, mtu)
|
||||
wg.me = link.NewMe(
|
||||
&wg.key,
|
||||
wg.c.IP+"/32",
|
||||
wg.c.EndPoint,
|
||||
lower.NewNIC(wg.c.IP, wg.c.SubNet, cidrs...),
|
||||
srcport, destport, mtu,
|
||||
)
|
||||
|
||||
for _, peer := range wg.c.Peers {
|
||||
var peerkey [32]byte
|
||||
|
||||
Reference in New Issue
Block a user