From 326d716e80e61b4f42b59a52edea64b6a420a1d0 Mon Sep 17 00:00:00 2001 From: Kusakabe Si Date: Mon, 13 Dec 2021 04:20:58 +0000 Subject: [PATCH] Fix bug: p2p mode querypeer not work --- .vscode/launch.json | 2 +- device/device.go | 28 ++++++++++---------- device/receive.go | 8 +++--- device/receivesendproc.go | 14 +++++----- device/send.go | 2 +- example_config/p2p_mode/EgNet_edge1.yaml | 10 +++---- example_config/p2p_mode/EgNet_edge2.yaml | 28 ++++++++++---------- example_config/p2p_mode/EgNet_edge3.yaml | 20 +++++++------- example_config/p2p_mode/EgNet_edge4.yaml | 20 +++++++------- example_config/p2p_mode/EgNet_edge5.yaml | 12 ++++----- example_config/p2p_mode/EgNet_edge6.yaml | 12 ++++----- example_config/p2p_mode/README.md | 2 +- example_config/p2p_mode/README_zh.md | 2 +- gencfg/example_conf.go | 33 +++++++++++++++++------- gencfg/gencfgNM.go | 29 ++++++++++++++------- gencfg/gencfgSM.go | 4 +-- main_edge.go | 4 +-- main_super.go | 6 ++--- 18 files changed, 131 insertions(+), 105 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index c8b29d4..3a949e5 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -32,7 +32,7 @@ "program": "${workspaceFolder}", "buildFlags": "-tags 'novpp'", "env": {"CGO_CFLAGS":"-I/usr/include/memif"}, - "args":["-config","example_config/super_mode/gensuper.yaml","-mode","gencfg","-cfgmode","super"/*,"-example"*/], + "args":["-config","example_config/p2p_mode/genp2p.yaml","-mode","gencfg","-cfgmode","p2p"/*,"-example"*/], } ] } \ No newline at end of file diff --git a/device/device.go b/device/device.go index 31e823e..bfe6a0f 100644 --- a/device/device.go +++ b/device/device.go @@ -86,7 +86,7 @@ type Device struct { Chan_server_register chan mtypes.RegisterMsg Chan_server_pong chan mtypes.PongMsg Chan_save_config chan struct{} - Chan_Supernode_OK chan struct{} + Chan_Edge_Initialized chan struct{} Chan_SendPingStart chan struct{} Chan_SendRegisterStart chan struct{} Chan_HttpPostStart chan struct{} @@ -367,25 +367,27 @@ func NewDevice(tapDevice tap.Device, id mtypes.Vertex, bind conn.Bind, logger *L device.DupData = *fixed_time_cache.NewCache(mtypes.S2TD(econfig.DynamicRoute.DupCheckTimeout), false, mtypes.S2TD(60)) device.event_tryendpoint = make(chan struct{}, 1<<6) device.Chan_save_config = make(chan struct{}, 1<<5) - device.Chan_Supernode_OK = make(chan struct{}, 1<<5) + device.Chan_Edge_Initialized = make(chan struct{}, 1<<5) device.Chan_SendPingStart = make(chan struct{}, 1<<5) device.Chan_SendRegisterStart = make(chan struct{}, 1<<5) device.Chan_HttpPostStart = make(chan struct{}, 1<<5) device.LogLevel = econfig.LogLevel device.SuperConfig.DampingResistance = device.EdgeConfig.DynamicRoute.DampingResistance - go device.RoutineSetEndpoint() - go device.RoutineDetectOfflineAndTryNextEndpoint() - go device.RoutineRegister(device.Chan_SendRegisterStart) - go device.RoutineSendPing(device.Chan_SendPingStart) - go device.RoutineSpreadAllMyNeighbor() - go device.RoutineResetConn() - go device.RoutineClearL2FIB() - go device.RoutineRecalculateNhTable() - go device.RoutinePostPeerInfo(device.Chan_HttpPostStart) go func() { - <-device.Chan_Supernode_OK - device.Chan_SendRegisterStart <- struct{}{} + <-device.Chan_Edge_Initialized + if device.LogLevel.LogInternal { + fmt.Printf("Internal: Edge initialized, start background loops\n") + } + go device.RoutineSetEndpoint() + go device.RoutineDetectOfflineAndTryNextEndpoint() + go device.RoutineRegister(device.Chan_SendRegisterStart) + go device.RoutineSendPing(device.Chan_SendPingStart) + go device.RoutineSpreadAllMyNeighbor() + go device.RoutineResetConn() + go device.RoutineClearL2FIB() + go device.RoutineRecalculateNhTable() + go device.RoutinePostPeerInfo(device.Chan_HttpPostStart) }() } diff --git a/device/receive.go b/device/receive.go index 59903b4..ef16929 100644 --- a/device/receive.go +++ b/device/receive.go @@ -538,7 +538,7 @@ func (peer *Peer) RoutineSequentialReceiver() { should_transfer = true } else { if device.LogLevel.LogTransit { - fmt.Printf("Transit: Duplicate packet dropped. From:%v Me:%v To:%v S:%v D:%v\n", peer.ID, device.ID, peer_out.ID, src_nodeID.ToString(), dst_nodeID.ToString()) + fmt.Printf("Transit: Duplicate packet dropped. S:%v D:%v From:%v \n", src_nodeID.ToString(), dst_nodeID.ToString(), peer.ID) } goto skip } @@ -577,7 +577,7 @@ func (peer *Peer) RoutineSequentialReceiver() { peer_out = device.peers.IDMap[next_id] device.peers.RUnlock() if device.LogLevel.LogTransit { - fmt.Printf("Transit: Transfer From:%v Me:%v To:%v S:%v D:%v\n", peer.ID, device.ID, peer_out.ID, src_nodeID.ToString(), dst_nodeID.ToString()) + fmt.Printf("Transit: Transfer From:%v Me:%v To:%v S:%v D:%v TTL:%v\n", peer.ID, device.ID, peer_out.ID, src_nodeID.ToString(), dst_nodeID.ToString(), l2ttl) } go device.SendPacket(peer_out, elem.Type, l2ttl, elem.packet, MessageTransportOffsetContent) } else { @@ -593,7 +593,7 @@ func (peer *Peer) RoutineSequentialReceiver() { if packet_type != path.NormalPacket { if device.LogLevel.LogControl { if peer.GetEndpointDstStr() != "" { - fmt.Printf("Control: Recv %v S:%v D:%v From:%v IP:%v\n", device.sprint_received(packet_type, elem.packet[path.EgHeaderLen:]), src_nodeID.ToString(), dst_nodeID.ToString(), peer.ID.ToString(), peer.GetEndpointDstStr()) + fmt.Printf("Control: Recv %v S:%v D:%v TTL:%v From:%v IP:%v\n", device.sprint_received(packet_type, elem.packet[path.EgHeaderLen:]), src_nodeID.ToString(), dst_nodeID.ToString(), elem.TTL, peer.ID.ToString(), peer.GetEndpointDstStr()) } } err = device.process_received(packet_type, peer, elem.packet[path.EgHeaderLen:]) @@ -611,7 +611,7 @@ func (peer *Peer) RoutineSequentialReceiver() { } if device.LogLevel.LogNormal { packet_len := len(elem.packet) - path.EgHeaderLen - fmt.Printf("Normal: Recv Len:%v S:%v D:%v From:%v IP:%v:\n", strconv.Itoa(packet_len), src_nodeID.ToString(), dst_nodeID.ToString(), peer.ID.ToString(), peer.GetEndpointDstStr()) + fmt.Printf("Normal: Recv Len:%v S:%v D:%v TTL:%v From:%v IP:%v:\n", strconv.Itoa(packet_len), src_nodeID.ToString(), dst_nodeID.ToString(), elem.TTL, peer.ID.ToString(), peer.GetEndpointDstStr()) packet := gopacket.NewPacket(elem.packet[path.EgHeaderLen:], layers.LayerTypeEthernet, gopacket.Default) fmt.Println(packet.Dump()) } diff --git a/device/receivesendproc.go b/device/receivesendproc.go index 1a0f06c..0fba451 100644 --- a/device/receivesendproc.go +++ b/device/receivesendproc.go @@ -46,7 +46,7 @@ func (device *Device) SendPacket(peer *Peer, usage path.Usage, ttl uint8, packet if usage == path.NormalPacket && EgHeader.GetSrc() == device.ID { dst_nodeID := EgHeader.GetDst() packet_len := len(packet) - path.EgHeaderLen - fmt.Printf("Normal: Send Len:%v S:%v D:%v To:%v IP:%v:\n", packet_len, device.ID.ToString(), dst_nodeID.ToString(), peer.ID.ToString(), peer.GetEndpointDstStr()) + fmt.Printf("Normal: Send Len:%v S:%v D:%v TTL:%v To:%v IP:%v:\n", packet_len, device.ID.ToString(), dst_nodeID.ToString(), ttl, peer.ID.ToString(), peer.GetEndpointDstStr()) packet := gopacket.NewPacket(packet[path.EgHeaderLen:], layers.LayerTypeEthernet, gopacket.Default) fmt.Println(packet.Dump()) } @@ -57,7 +57,7 @@ func (device *Device) SendPacket(peer *Peer, usage path.Usage, ttl uint8, packet if peer.GetEndpointDstStr() != "" { src_nodeID := EgHeader.GetSrc() dst_nodeID := EgHeader.GetDst() - fmt.Printf("Control: Send %v S:%v D:%v To:%v IP:%v\n", device.sprint_received(usage, packet[path.EgHeaderLen:]), src_nodeID.ToString(), dst_nodeID.ToString(), peer.ID.ToString(), peer.GetEndpointDstStr()) + fmt.Printf("Control: Send %v S:%v D:%v TTL:%v To:%v IP:%v\n", device.sprint_received(usage, packet[path.EgHeaderLen:]), src_nodeID.ToString(), dst_nodeID.ToString(), ttl, peer.ID.ToString(), peer.GetEndpointDstStr()) } } } @@ -94,8 +94,8 @@ func (device *Device) SpreadPacket(skip_list map[mtypes.Vertex]bool, usage path. device.peers.RLock() for peer_id, peer_out := range device.peers.IDMap { if _, ok := skip_list[peer_id]; ok { - if device.LogLevel.LogTransit { - fmt.Printf("Transit: Skipped Spread Packet packet through %d to %d\n", device.ID, peer_out.ID) + if device.LogLevel.LogTransit && peer_out.endpoint != nil { + fmt.Printf("Transit: Skipped Spread Packet packet Me:%v To:%d TTL:%v\n", device.ID, peer_out.ID, ttl) } continue } @@ -115,7 +115,7 @@ func (device *Device) TransitBoardcastPacket(src_nodeID mtypes.Vertex, in_id mty for peer_id := range node_boardcast_list { peer_out := device.peers.IDMap[peer_id] if device.LogLevel.LogTransit { - fmt.Printf("Transit: Transfer packet from %d through %d to %d\n", in_id, device.ID, peer_out.ID) + fmt.Printf("Transit: Transfer From:%v Me:%v To:%v S:%v D:%v TTL:%v\n", in_id, device.ID, peer_out.ID, src_nodeID.ToString(), peer_out.ID.ToString(), ttl) } go device.SendPacket(peer_out, usage, ttl, packet, offset) } @@ -377,6 +377,7 @@ func (device *Device) process_pong(peer *Peer, content mtypes.PongMsg) error { buf := make([]byte, path.EgHeaderLen+len(body)) header, _ := path.NewEgHeader(buf[:path.EgHeaderLen], device.EdgeConfig.Interface.MTU) header.SetSrc(device.ID) + header.SetDst(mtypes.NodeID_Spread) copy(buf[path.EgHeaderLen:], body) device.SendPacket(peer, path.QueryPeer, device.EdgeConfig.DefaultTTL, buf, MessageTransportOffsetContent) } @@ -811,11 +812,12 @@ func (device *Device) RoutineDetectOfflineAndTryNextEndpoint() { } } -func (device *Device) RoutineSendPing(startchan <-chan struct{}) { +func (device *Device) RoutineSendPing(startchan chan struct{}) { if !(device.EdgeConfig.DynamicRoute.P2P.UseP2P || device.EdgeConfig.DynamicRoute.SuperNode.UseSuperNode) { return } var waitchan <-chan time.Time + startchan <- struct{}{} for { if device.EdgeConfig.DynamicRoute.SendPingInterval > 0 { waitchan = time.After(mtypes.S2TD(device.EdgeConfig.DynamicRoute.SendPingInterval)) diff --git a/device/send.go b/device/send.go index 8dcc355..03501ae 100644 --- a/device/send.go +++ b/device/send.go @@ -287,7 +287,7 @@ func (device *Device) RoutineReadFromTUN() { } if device.LogLevel.LogNormal { packet_len := len(elem.packet) - path.EgHeaderLen - fmt.Printf("Normal: Send Len:%v S:%v D:%v To:%v IP:%v:\n", packet_len, device.ID.ToString(), dst_nodeID.ToString(), peer.ID.ToString(), peer.GetEndpointDstStr()) + fmt.Printf("Normal: Send Len:%v S:%v D:%v TTL:%v To:%v IP:%v:\n", packet_len, device.ID.ToString(), dst_nodeID.ToString(), elem.TTL, peer.ID.ToString(), peer.GetEndpointDstStr()) packet := gopacket.NewPacket(elem.packet[path.EgHeaderLen:], layers.LayerTypeEthernet, gopacket.Default) fmt.Println(packet.Dump()) } diff --git a/example_config/p2p_mode/EgNet_edge1.yaml b/example_config/p2p_mode/EgNet_edge1.yaml index f6a3226..3afd331 100644 --- a/example_config/p2p_mode/EgNet_edge1.yaml +++ b/example_config/p2p_mode/EgNet_edge1.yaml @@ -3,7 +3,7 @@ Interface: Name: tap1 VPPIFaceID: 1 VPPBridgeID: 4242 - MacAddrPrefix: 26:E9:46:C5 + MacAddrPrefix: B2:D1:AB:85 IPv4CIDR: 192.168.76.0/24 IPv6CIDR: fd95:71cb:a3df:e586::/64 IPv6LLPrefix: fe80::a3df:0/112 @@ -16,7 +16,7 @@ NodeName: EgNet1 PostScript: "" DefaultTTL: 200 L2FIBTimeout: 3600 -PrivKey: m+okCrSHKbhaAw1MycIf9+i1mnl/PXQFBx9q6Alfa7Y= +PrivKey: x63jMG2oFSznZqwtCO2rW4ox7n+ljpP+1gIPyL/a5sI= ListenPort: 3001 LogLevel: LogLevel: error @@ -31,7 +31,7 @@ DynamicRoute: TimeoutCheckInterval: 20 ConnNextTry: 5 DupCheckTimeout: 40 - AdditionalCost: 10 + AdditionalCost: 1000 DampingResistance: 0.95 SaveNewPeers: false SuperNode: @@ -64,8 +64,8 @@ NextHopTable: {} ResetConnInterval: 86400 Peers: - NodeID: 2 - PubKey: FRPoFmNczfXChxHcyqUB/DlP8uilmULXJ53rkXKbRnA= - PSKey: F04akG91pDuDPSpeiorm1RBZTspDqpk5xbWg1ywW2qA= + PubKey: x1A7t6DdG4XSLAud3yeEyEJ1eJVQ4QVhielSKbxptDM= + PSKey: TFIU3FbTQE/1Tiv8GnAsE/vxV9LDAD8zNqlzE2/FyJU= EndPoint: 127.0.0.1:3002 PersistentKeepalive: 0 Static: true diff --git a/example_config/p2p_mode/EgNet_edge2.yaml b/example_config/p2p_mode/EgNet_edge2.yaml index 5498926..8a11fdd 100644 --- a/example_config/p2p_mode/EgNet_edge2.yaml +++ b/example_config/p2p_mode/EgNet_edge2.yaml @@ -3,7 +3,7 @@ Interface: Name: tap1 VPPIFaceID: 1 VPPBridgeID: 4242 - MacAddrPrefix: 26:E9:46:C5 + MacAddrPrefix: B2:D1:AB:85 IPv4CIDR: 192.168.76.0/24 IPv6CIDR: fd95:71cb:a3df:e586::/64 IPv6LLPrefix: fe80::a3df:0/112 @@ -16,7 +16,7 @@ NodeName: EgNet2 PostScript: "" DefaultTTL: 200 L2FIBTimeout: 3600 -PrivKey: F1rQITtaIzm4uGI83znW7hXRA/brORBYh9nYE1T20TQ= +PrivKey: u7jv20ZmBtWYexIV8Bv8pmjwyxzeVCaikYl4P+CDkwc= ListenPort: 3002 LogLevel: LogLevel: error @@ -31,8 +31,8 @@ DynamicRoute: TimeoutCheckInterval: 20 ConnNextTry: 5 DupCheckTimeout: 40 - AdditionalCost: 10 - DampingResistance: 0.9 + AdditionalCost: 1000 + DampingResistance: 0.95 SaveNewPeers: false SuperNode: UseSuperNode: false @@ -63,21 +63,21 @@ DynamicRoute: NextHopTable: {} ResetConnInterval: 86400 Peers: -- NodeID: 4 - PubKey: kSH8k+0tx67ExXNXYLElgnMaLQDxqPQ3wIUv2CRXKSc= - PSKey: wFwfJeWIBTZw3eAQxBK7mM70cZOllNnCoOnUJC0008g= - EndPoint: 127.0.0.1:3004 - PersistentKeepalive: 0 - Static: true - NodeID: 1 - PubKey: Da0+2BD/tyz38YuAJ7Ltfm8N+tetzo/0YwyqY9PCrRw= - PSKey: F04akG91pDuDPSpeiorm1RBZTspDqpk5xbWg1ywW2qA= + PubKey: ixuv4jI0H95Ym1+lmLh4TLrq/a/f+EEXuaYzWVIRbGs= + PSKey: TFIU3FbTQE/1Tiv8GnAsE/vxV9LDAD8zNqlzE2/FyJU= EndPoint: 127.0.0.1:3001 PersistentKeepalive: 0 Static: true - NodeID: 3 - PubKey: Xv/1VqAxaB+ZYSBg2PeL+oeyi05U+PHdXjoUeHuX7Rs= - PSKey: Cijbh7tHoGbwVANl/3x7qtDHbe3bO9lpOFXoU4hp8w8= + PubKey: FlNRAKQu/X3H4k03tmfIAbw3yoGOVJt59Ff5lBAqRhE= + PSKey: ac1v88xBD14viltWV2/lfSk2ODvu4yiZ0GjgIn2PCMQ= EndPoint: 127.0.0.1:3003 PersistentKeepalive: 0 Static: true +- NodeID: 4 + PubKey: XCHI8Nza874YfCQAMVp7qtsd1GjOH7LbcDLg58NYli4= + PSKey: BV14aWGhnC3ZBWGGazT+6Mk4RQ7PzY/+c3e4vN2OBNQ= + EndPoint: 127.0.0.1:3004 + PersistentKeepalive: 0 + Static: true diff --git a/example_config/p2p_mode/EgNet_edge3.yaml b/example_config/p2p_mode/EgNet_edge3.yaml index 3e610b5..30fe362 100644 --- a/example_config/p2p_mode/EgNet_edge3.yaml +++ b/example_config/p2p_mode/EgNet_edge3.yaml @@ -3,7 +3,7 @@ Interface: Name: tap1 VPPIFaceID: 1 VPPBridgeID: 4242 - MacAddrPrefix: 26:E9:46:C5 + MacAddrPrefix: B2:D1:AB:85 IPv4CIDR: 192.168.76.0/24 IPv6CIDR: fd95:71cb:a3df:e586::/64 IPv6LLPrefix: fe80::a3df:0/112 @@ -16,7 +16,7 @@ NodeName: EgNet3 PostScript: "" DefaultTTL: 200 L2FIBTimeout: 3600 -PrivKey: +zc8mBj65eA/J7RAVRnsRxAfoi45fgipiyqL9kmsqdM= +PrivKey: 4HjyHIBHzF1DDP6FwzgWWf3/mvuyCBKE2l0m0otZ6/w= ListenPort: 3003 LogLevel: LogLevel: error @@ -31,8 +31,8 @@ DynamicRoute: TimeoutCheckInterval: 20 ConnNextTry: 5 DupCheckTimeout: 40 - AdditionalCost: 10 - DampingResistance: 0.9 + AdditionalCost: 1000 + DampingResistance: 0.95 SaveNewPeers: false SuperNode: UseSuperNode: false @@ -64,20 +64,20 @@ NextHopTable: {} ResetConnInterval: 86400 Peers: - NodeID: 2 - PubKey: FRPoFmNczfXChxHcyqUB/DlP8uilmULXJ53rkXKbRnA= - PSKey: Cijbh7tHoGbwVANl/3x7qtDHbe3bO9lpOFXoU4hp8w8= + PubKey: x1A7t6DdG4XSLAud3yeEyEJ1eJVQ4QVhielSKbxptDM= + PSKey: ac1v88xBD14viltWV2/lfSk2ODvu4yiZ0GjgIn2PCMQ= EndPoint: 127.0.0.1:3002 PersistentKeepalive: 0 Static: true - NodeID: 4 - PubKey: kSH8k+0tx67ExXNXYLElgnMaLQDxqPQ3wIUv2CRXKSc= - PSKey: mAgQbX34b3f/geVEU7bn1y4AqA6Eu+ZY9PR1d6IEkDg= + PubKey: XCHI8Nza874YfCQAMVp7qtsd1GjOH7LbcDLg58NYli4= + PSKey: XN6RwX2w7VIUKao7Qmp+Q+ltF5S2fFuphsyxyeTS1v8= EndPoint: 127.0.0.1:3004 PersistentKeepalive: 0 Static: true - NodeID: 5 - PubKey: 6GTxl1C65KC2wV0bXDVSnp6f3FdtjUhhDWZF4Ipt6gY= - PSKey: 5Ph+d0SFW7hQ8LibICiXcpWpWnaI7i3T1J5Zmw8km3w= + PubKey: C0YMktiJW0g1pa22D2ES6nu5ikXoD2PhC437t3VWXTc= + PSKey: 67h6hs+l6FfZCi8sVHcvZlcVxFPRjFIX8qKlXQphWs4= EndPoint: 127.0.0.1:3005 PersistentKeepalive: 0 Static: true diff --git a/example_config/p2p_mode/EgNet_edge4.yaml b/example_config/p2p_mode/EgNet_edge4.yaml index 4021436..6d3817b 100644 --- a/example_config/p2p_mode/EgNet_edge4.yaml +++ b/example_config/p2p_mode/EgNet_edge4.yaml @@ -3,7 +3,7 @@ Interface: Name: tap1 VPPIFaceID: 1 VPPBridgeID: 4242 - MacAddrPrefix: 26:E9:46:C5 + MacAddrPrefix: B2:D1:AB:85 IPv4CIDR: 192.168.76.0/24 IPv6CIDR: fd95:71cb:a3df:e586::/64 IPv6LLPrefix: fe80::a3df:0/112 @@ -16,7 +16,7 @@ NodeName: EgNet4 PostScript: "" DefaultTTL: 200 L2FIBTimeout: 3600 -PrivKey: DW1nI8xKiaYJRJYUwQaZKNLRVKIVl1unF4YKzmYfNZE= +PrivKey: aPe9FxqEPtMT5AYVmGx2aQmog0GJvXjzJoty+3ztbzs= ListenPort: 3004 LogLevel: LogLevel: error @@ -31,8 +31,8 @@ DynamicRoute: TimeoutCheckInterval: 20 ConnNextTry: 5 DupCheckTimeout: 40 - AdditionalCost: 10 - DampingResistance: 0.9 + AdditionalCost: 1000 + DampingResistance: 0.95 SaveNewPeers: false SuperNode: UseSuperNode: false @@ -64,20 +64,20 @@ NextHopTable: {} ResetConnInterval: 86400 Peers: - NodeID: 2 - PubKey: FRPoFmNczfXChxHcyqUB/DlP8uilmULXJ53rkXKbRnA= - PSKey: wFwfJeWIBTZw3eAQxBK7mM70cZOllNnCoOnUJC0008g= + PubKey: x1A7t6DdG4XSLAud3yeEyEJ1eJVQ4QVhielSKbxptDM= + PSKey: BV14aWGhnC3ZBWGGazT+6Mk4RQ7PzY/+c3e4vN2OBNQ= EndPoint: 127.0.0.1:3002 PersistentKeepalive: 0 Static: true - NodeID: 3 - PubKey: Xv/1VqAxaB+ZYSBg2PeL+oeyi05U+PHdXjoUeHuX7Rs= - PSKey: mAgQbX34b3f/geVEU7bn1y4AqA6Eu+ZY9PR1d6IEkDg= + PubKey: FlNRAKQu/X3H4k03tmfIAbw3yoGOVJt59Ff5lBAqRhE= + PSKey: XN6RwX2w7VIUKao7Qmp+Q+ltF5S2fFuphsyxyeTS1v8= EndPoint: 127.0.0.1:3003 PersistentKeepalive: 0 Static: true - NodeID: 6 - PubKey: XagHQGIw/3Y1btg/gCWYbQMOB5RsOeJRP5i/w5bzf14= - PSKey: n44pByAV/umw2EtfP90jn2A1Hq/mzXCRrT6nXQKlJfw= + PubKey: 7b9o5yZuebAZVjlvLvJzLH20lg4mCfMTSPXe0iJPjiA= + PSKey: RYwSBskLDa4pW2TiBDAmXIAW2Cs1LOiA/J/FfKAGmDY= EndPoint: 127.0.0.1:3006 PersistentKeepalive: 0 Static: true diff --git a/example_config/p2p_mode/EgNet_edge5.yaml b/example_config/p2p_mode/EgNet_edge5.yaml index 4dd345e..f884eda 100644 --- a/example_config/p2p_mode/EgNet_edge5.yaml +++ b/example_config/p2p_mode/EgNet_edge5.yaml @@ -3,7 +3,7 @@ Interface: Name: tap1 VPPIFaceID: 1 VPPBridgeID: 4242 - MacAddrPrefix: 26:E9:46:C5 + MacAddrPrefix: B2:D1:AB:85 IPv4CIDR: 192.168.76.0/24 IPv6CIDR: fd95:71cb:a3df:e586::/64 IPv6LLPrefix: fe80::a3df:0/112 @@ -16,7 +16,7 @@ NodeName: EgNet5 PostScript: "" DefaultTTL: 200 L2FIBTimeout: 3600 -PrivKey: 0zI7tZlrD57Xj0u2qo7zfcqWslpUqaYPpxIp9nZSI1s= +PrivKey: 83XsoCxkCbDF4lx6KlyybL5qJZWR/Tn7nHmABsLh2Fo= ListenPort: 3005 LogLevel: LogLevel: error @@ -31,8 +31,8 @@ DynamicRoute: TimeoutCheckInterval: 20 ConnNextTry: 5 DupCheckTimeout: 40 - AdditionalCost: 10 - DampingResistance: 0.9 + AdditionalCost: 1000 + DampingResistance: 0.95 SaveNewPeers: false SuperNode: UseSuperNode: false @@ -64,8 +64,8 @@ NextHopTable: {} ResetConnInterval: 86400 Peers: - NodeID: 3 - PubKey: Xv/1VqAxaB+ZYSBg2PeL+oeyi05U+PHdXjoUeHuX7Rs= - PSKey: 5Ph+d0SFW7hQ8LibICiXcpWpWnaI7i3T1J5Zmw8km3w= + PubKey: FlNRAKQu/X3H4k03tmfIAbw3yoGOVJt59Ff5lBAqRhE= + PSKey: 67h6hs+l6FfZCi8sVHcvZlcVxFPRjFIX8qKlXQphWs4= EndPoint: 127.0.0.1:3003 PersistentKeepalive: 0 Static: true diff --git a/example_config/p2p_mode/EgNet_edge6.yaml b/example_config/p2p_mode/EgNet_edge6.yaml index d61e6da..ef8d682 100644 --- a/example_config/p2p_mode/EgNet_edge6.yaml +++ b/example_config/p2p_mode/EgNet_edge6.yaml @@ -3,7 +3,7 @@ Interface: Name: tap1 VPPIFaceID: 1 VPPBridgeID: 4242 - MacAddrPrefix: 26:E9:46:C5 + MacAddrPrefix: B2:D1:AB:85 IPv4CIDR: 192.168.76.0/24 IPv6CIDR: fd95:71cb:a3df:e586::/64 IPv6LLPrefix: fe80::a3df:0/112 @@ -16,7 +16,7 @@ NodeName: EgNet6 PostScript: "" DefaultTTL: 200 L2FIBTimeout: 3600 -PrivKey: 4J/LdOJYHem4ZJyzqniN4VYZcSiBZy362grDDovYVzc= +PrivKey: s07iDqaZ/rw21A3QxX/MPcv8Tm5Xkv1D+WEg1SreMSs= ListenPort: 3006 LogLevel: LogLevel: error @@ -31,8 +31,8 @@ DynamicRoute: TimeoutCheckInterval: 20 ConnNextTry: 5 DupCheckTimeout: 40 - AdditionalCost: 10 - DampingResistance: 0.9 + AdditionalCost: 1000 + DampingResistance: 0.95 SaveNewPeers: false SuperNode: UseSuperNode: false @@ -64,8 +64,8 @@ NextHopTable: {} ResetConnInterval: 86400 Peers: - NodeID: 4 - PubKey: kSH8k+0tx67ExXNXYLElgnMaLQDxqPQ3wIUv2CRXKSc= - PSKey: n44pByAV/umw2EtfP90jn2A1Hq/mzXCRrT6nXQKlJfw= + PubKey: XCHI8Nza874YfCQAMVp7qtsd1GjOH7LbcDLg58NYli4= + PSKey: RYwSBskLDa4pW2TiBDAmXIAW2Cs1LOiA/J/FfKAGmDY= EndPoint: 127.0.0.1:3004 PersistentKeepalive: 0 Static: true diff --git a/example_config/p2p_mode/README.md b/example_config/p2p_mode/README.md index c353c77..0e0db34 100644 --- a/example_config/p2p_mode/README.md +++ b/example_config/p2p_mode/README.md @@ -37,7 +37,7 @@ Edge Nodes: # Node related settings Run this, it will generate the required configuration file ``` -./etherguard-go -mode gencfg -cfgmode p2p -config example_config/p2p_mode/gensp2p.yaml +./etherguard-go -mode gencfg -cfgmode p2p -config example_config/p2p_mode/genp2p.yaml ``` Deploy these configuration files to the corresponding nodes, and then execute diff --git a/example_config/p2p_mode/README_zh.md b/example_config/p2p_mode/README_zh.md index 8d2da56..9c403e5 100644 --- a/example_config/p2p_mode/README_zh.md +++ b/example_config/p2p_mode/README_zh.md @@ -35,7 +35,7 @@ Edge Nodes: # 所有的節點相關設定 ``` 接著執行這個,就會生成所需設定檔了。 ``` -./etherguard-go -mode gencfg -cfgmode p2p -config example_config/p2p_mode/gensp2p.yaml +./etherguard-go -mode gencfg -cfgmode p2p -config example_config/p2p_mode/genp2p.yaml ``` 把這些設定檔不捨去對應節點,然後再執行 diff --git a/gencfg/example_conf.go b/gencfg/example_conf.go index 7d4b12c..2996902 100644 --- a/gencfg/example_conf.go +++ b/gencfg/example_conf.go @@ -6,17 +6,21 @@ package gencfg import ( + "fmt" + "io/fs" + "github.com/KusakabeSi/EtherGuard-VPN/device" "github.com/KusakabeSi/EtherGuard-VPN/mtypes" "github.com/KusakabeSi/EtherGuard-VPN/path" ) -func GetExampleEdgeConf(templatePath string, getDemo bool) mtypes.EdgeConfig { +func GetExampleEdgeConf(templatePath string, getDemo bool) (mtypes.EdgeConfig, error) { econfig := mtypes.EdgeConfig{} + var err error if templatePath != "" { - err := mtypes.ReadYaml(templatePath, &econfig) + err = mtypes.ReadYaml(templatePath, &econfig) if err == nil { - return econfig + return econfig, nil } } v1 := mtypes.Vertex(1) @@ -137,7 +141,7 @@ func GetExampleEdgeConf(templatePath string, getDemo bool) mtypes.EdgeConfig { }, } if getDemo { - g, _ := path.NewGraph(3, false, econfig.DynamicRoute.P2P.GraphRecalculateSetting, econfig.DynamicRoute.NTPConfig, mtypes.LoggerInfo{}) + g, _ := path.NewGraph(3, false, mtypes.GraphRecalculateSetting{}, mtypes.NTPInfo{}, mtypes.LoggerInfo{}) g.UpdateLatency(1, 2, 0.5, 99999, 0, false, false) g.UpdateLatency(2, 1, 0.5, 99999, 0, false, false) g.UpdateLatency(2, 3, 0.5, 99999, 0, false, false) @@ -160,15 +164,16 @@ func GetExampleEdgeConf(templatePath string, getDemo bool) mtypes.EdgeConfig { econfig.DynamicRoute.SuperNode.EndpointV4 = "" econfig.DynamicRoute.SuperNode.EndpointV6 = "" } - return econfig + return econfig, &fs.PathError{Path: "", Err: fmt.Errorf("no path provided")} } -func GetExampleSuperConf(templatePath string, getDemo bool) mtypes.SuperConfig { +func GetExampleSuperConf(templatePath string, getDemo bool) (mtypes.SuperConfig, error) { sconfig := mtypes.SuperConfig{} + var err error if templatePath != "" { - err := mtypes.ReadYaml(templatePath, &sconfig) + err = mtypes.ReadYaml(templatePath, &sconfig) if err == nil { - return sconfig + return sconfig, nil } } @@ -207,7 +212,15 @@ func GetExampleSuperConf(templatePath string, getDemo bool) mtypes.SuperConfig { UpdateSuper: random_passwd + "_updatesuper", }, GraphRecalculateSetting: mtypes.GraphRecalculateSetting{ - StaticMode: false, + StaticMode: false, + ManualLatency: mtypes.DistTable{ + mtypes.Vertex(1): { + mtypes.Vertex(2): 1.14, + }, + mtypes.Vertex(2): { + mtypes.Vertex(1): 5.14, + }, + }, JitterTolerance: 30, JitterToleranceMultiplier: 1.01, TimeoutCheckInterval: 5, @@ -245,5 +258,5 @@ func GetExampleSuperConf(templatePath string, getDemo bool) mtypes.SuperConfig { sconfig.NextHopTable = make(mtypes.NextHopTable) sconfig.GraphRecalculateSetting.ManualLatency = make(mtypes.DistTable) } - return sconfig + return sconfig, &fs.PathError{Path: "", Err: fmt.Errorf("no path provided")} } diff --git a/gencfg/gencfgNM.go b/gencfg/gencfgNM.go index aabe00e..21433f4 100644 --- a/gencfg/gencfgNM.go +++ b/gencfg/gencfgNM.go @@ -162,21 +162,30 @@ func GenNMCfg(NMCinfigPath string, enableP2P bool, printExample bool) (err error if err != nil { fmt.Println("Error:", err) } - nhTableStr, _ := yaml.Marshal(next) - fmt.Println(string(nhTableStr)) + if NMCfg.DistanceMatrix != "" && !enableP2P { + nhTableStr, _ := yaml.Marshal(next) + fmt.Println(string(nhTableStr)) + } all_vert := g.Vertices() - for u := range all_vert { - for v := range all_vert { - if u != v { - path, err := g.Path(u, v) - if err != nil { - return fmt.Errorf("couldn't find path from %v to %v: %v", u, v, err) + if NMCfg.DistanceMatrix != "" { + for u := range all_vert { + for v := range all_vert { + if u != v { + path, err := g.Path(u, v) + if err != nil { + return fmt.Errorf("couldn't find path from %v to %v: %v", u, v, err) + } + fmt.Printf("%d -> %d\t%3f\t%v\n", u, v, dist[u][v], path) } - fmt.Printf("%d -> %d\t%3f\t%v\n", u, v, dist[u][v], path) } } } - econfig := GetExampleEdgeConf(NMCfg.EdgeConfigTemplate, false) + econfig, err := GetExampleEdgeConf(NMCfg.EdgeConfigTemplate, false) + if err != nil { + if enableP2P { + econfig.DynamicRoute.AdditionalCost = 1000 + } + } econfig.DynamicRoute.P2P.UseP2P = enableP2P econfig.DynamicRoute.SuperNode.UseSuperNode = false econfig.NextHopTable = next diff --git a/gencfg/gencfgSM.go b/gencfg/gencfgSM.go index bd9faa0..8334b7c 100644 --- a/gencfg/gencfgSM.go +++ b/gencfg/gencfgSM.go @@ -159,7 +159,7 @@ func GenSuperCfg(SMCinfigPath string, printExample bool) (err error) { } } - sconfig := GetExampleSuperConf(SMCfg.SuperConfigTemplate, false) + sconfig, _ := GetExampleSuperConf(SMCfg.SuperConfigTemplate, false) if len(SMCfg.NetworkName) > 10 { return fmt.Errorf("Name too long") @@ -253,7 +253,7 @@ func GenSuperCfg(SMCinfigPath string, printExample bool) (err error) { sconfig.PrivKeyV4 = PrivKeyS4.ToString() sconfig.PrivKeyV6 = PrivKeyS6.ToString() allec := make(map[mtypes.Vertex]mtypes.EdgeConfig) - peerceconf := GetExampleEdgeConf(sconfig.EdgeTemplate, false) + peerceconf, _ := GetExampleEdgeConf(sconfig.EdgeTemplate, false) for _, ii := range NodeIDs { i := mtypes.Vertex(ii) PSKeyE := device.RandomPSK() diff --git a/main_edge.go b/main_edge.go index 4494477..7da85ba 100644 --- a/main_edge.go +++ b/main_edge.go @@ -27,7 +27,7 @@ import ( ) func printExampleEdgeConf() { - tconfig := gencfg.GetExampleEdgeConf("", true) + tconfig, _ := gencfg.GetExampleEdgeConf("", true) toprint, _ := yaml.Marshal(tconfig) fmt.Print(string(toprint)) } @@ -201,7 +201,6 @@ func Edge(configPath string, useUAPI bool, printExample bool, bindmode string) ( return errors.New("failed to connect to supernode") } } - the_device.Chan_Supernode_OK <- struct{}{} } logger.Verbosef("Device started") @@ -258,6 +257,7 @@ func Edge(configPath string, useUAPI bool, printExample bool, bindmode string) ( signal.Notify(term, syscall.SIGTERM) signal.Notify(term, os.Interrupt) + the_device.Chan_Edge_Initialized <- struct{}{} mtypes.SdNotify(false, mtypes.SdNotifyReady) SdNotify, err := mtypes.SdNotify(false, mtypes.SdNotifyReady) if econfig.LogLevel.LogInternal { diff --git a/main_super.go b/main_super.go index dc5fe45..929ea05 100644 --- a/main_super.go +++ b/main_super.go @@ -62,7 +62,7 @@ func checkNhTable(NhTable mtypes.NextHopTable, peers []mtypes.SuperPeerInfo) err } func printExampleSuperConf() { - sconfig := gencfg.GetExampleSuperConf("", true) + sconfig, _ := gencfg.GetExampleSuperConf("", true) scprint, _ := yaml.Marshal(sconfig) fmt.Print(string(scprint)) } @@ -80,7 +80,7 @@ func Super(configPath string, useUAPI bool, printExample bool, bindmode string) return err } httpobj.http_sconfig = &sconfig - http_econfig_tmp := gencfg.GetExampleEdgeConf(sconfig.EdgeTemplate, true) + http_econfig_tmp, _ := gencfg.GetExampleEdgeConf(sconfig.EdgeTemplate, true) httpobj.http_econfig_tmp = &http_econfig_tmp NodeName := sconfig.NodeName if len(NodeName) > 32 { @@ -136,7 +136,7 @@ func Super(configPath string, useUAPI bool, printExample bool, bindmode string) Event_server_pong: make(chan mtypes.PongMsg, 1<<5), Event_server_register: make(chan mtypes.RegisterMsg, 1<<5), } - httpobj.http_graph, err = path.NewGraph(3, true, sconfig.GraphRecalculateSetting, mtypes.NTPInfo{}, sconfig.LogLevel) + httpobj.http_graph, err = path.NewGraph(3, true, sconfig.GraphRecalculateSetting, mtypes.NTPInfo{}, mtypes.LoggerInfo{}) if err != nil { return err }