Fix bug: p2p mode querypeer not work

This commit is contained in:
Kusakabe Si 2021-12-13 04:20:58 +00:00
parent 3940553358
commit 326d716e80
18 changed files with 131 additions and 105 deletions

2
.vscode/launch.json vendored
View File

@ -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"*/],
}
]
}

View File

@ -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,13 +367,18 @@ 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 func() {
<-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)
@ -383,9 +388,6 @@ func NewDevice(tapDevice tap.Device, id mtypes.Vertex, bind conn.Bind, logger *L
go device.RoutineClearL2FIB()
go device.RoutineRecalculateNhTable()
go device.RoutinePostPeerInfo(device.Chan_HttpPostStart)
go func() {
<-device.Chan_Supernode_OK
device.Chan_SendRegisterStart <- struct{}{}
}()
}

View File

@ -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())
}

View File

@ -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))

View File

@ -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())
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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
```
把這些設定檔不捨去對應節點,然後再執行

View File

@ -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
}
}
@ -208,6 +213,14 @@ func GetExampleSuperConf(templatePath string, getDemo bool) mtypes.SuperConfig {
},
GraphRecalculateSetting: mtypes.GraphRecalculateSetting{
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")}
}

View File

@ -162,9 +162,12 @@ func GenNMCfg(NMCinfigPath string, enableP2P bool, printExample bool) (err error
if err != nil {
fmt.Println("Error:", err)
}
if NMCfg.DistanceMatrix != "" && !enableP2P {
nhTableStr, _ := yaml.Marshal(next)
fmt.Println(string(nhTableStr))
}
all_vert := g.Vertices()
if NMCfg.DistanceMatrix != "" {
for u := range all_vert {
for v := range all_vert {
if u != v {
@ -176,7 +179,13 @@ func GenNMCfg(NMCinfigPath string, enableP2P bool, printExample bool) (err error
}
}
}
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

View File

@ -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()

View File

@ -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 {

View File

@ -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
}