mirror of
https://github.com/KusakabeShi/EtherGuard-VPN.git
synced 2025-08-23 23:41:23 +02:00
Bugfix, save peer to file ok
This commit is contained in:
@@ -304,6 +304,7 @@ func (peer *Peer) SetEndpointFromPacket(endpoint conn.Endpoint) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
peer.Lock()
|
peer.Lock()
|
||||||
|
peer.device.SaveToConfig(peer, endpoint.DstToString())
|
||||||
peer.endpoint = endpoint
|
peer.endpoint = endpoint
|
||||||
peer.Unlock()
|
peer.Unlock()
|
||||||
}
|
}
|
||||||
|
@@ -353,6 +353,7 @@ func (device *Device) RoutineSetEndpoint() {
|
|||||||
//Send Ping message to it
|
//Send Ping message to it
|
||||||
packet, err := device.GeneratePingPacket(device.ID)
|
packet, err := device.GeneratePingPacket(device.ID)
|
||||||
device.SendPacket(thepeer, packet, MessageTransportOffsetContent)
|
device.SendPacket(thepeer, packet, MessageTransportOffsetContent)
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
@@ -369,12 +370,44 @@ func (device *Device) RoutineSetEndpoint() {
|
|||||||
}
|
}
|
||||||
time.Sleep(path.S2TD(device.DRoute.P2P.PeerAliveTimeout))
|
time.Sleep(path.S2TD(device.DRoute.P2P.PeerAliveTimeout))
|
||||||
if NextRun {
|
if NextRun {
|
||||||
go device.SaveConfig()
|
|
||||||
device.event_tryendpoint <- struct{}{}
|
device.event_tryendpoint <- struct{}{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (device *Device) SaveToConfig(thepeer *Peer, url string) {
|
||||||
|
if thepeer.LastPingReceived.Add(path.S2TD(device.DRoute.P2P.PeerAliveTimeout)).After(time.Now()) {
|
||||||
|
//Peer alives
|
||||||
|
return
|
||||||
|
}
|
||||||
|
foundInFile := false
|
||||||
|
pubkeystr := PubKey2Str(thepeer.handshake.remoteStatic)
|
||||||
|
pskstr := PSKeyStr(thepeer.handshake.presharedKey)
|
||||||
|
if bytes.Equal(thepeer.handshake.presharedKey[:], make([]byte, 32)) {
|
||||||
|
pskstr = ""
|
||||||
|
}
|
||||||
|
for _, peerfile := range device.EdgeConfig.Peers {
|
||||||
|
if peerfile.NodeID == thepeer.ID && peerfile.PubKey == pubkeystr {
|
||||||
|
foundInFile = true
|
||||||
|
if peerfile.Static == false {
|
||||||
|
peerfile.EndPoint = url
|
||||||
|
}
|
||||||
|
} else if peerfile.NodeID == thepeer.ID || peerfile.PubKey == pubkeystr {
|
||||||
|
panic("Found NodeID match " + strconv.Itoa(int(thepeer.ID)) + ", but PubKey Not match %s enrties in config file" + pubkeystr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !foundInFile {
|
||||||
|
device.EdgeConfig.Peers = append(device.EdgeConfig.Peers, config.PeerInfo{
|
||||||
|
NodeID: thepeer.ID,
|
||||||
|
PubKey: pubkeystr,
|
||||||
|
PSKey: pskstr,
|
||||||
|
EndPoint: url,
|
||||||
|
Static: false,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
go device.SaveConfig()
|
||||||
|
}
|
||||||
|
|
||||||
func (device *Device) SaveConfig() {
|
func (device *Device) SaveConfig() {
|
||||||
if device.DRoute.SaveNewPeers {
|
if device.DRoute.SaveNewPeers {
|
||||||
configbytes, _ := yaml.Marshal(device.EdgeConfig)
|
configbytes, _ := yaml.Marshal(device.EdgeConfig)
|
||||||
|
@@ -145,6 +145,8 @@ func (g *IG) UpdateLentancy(u, v config.Vertex, dt time.Duration, checkchange bo
|
|||||||
}
|
}
|
||||||
func (g IG) Vertices() map[config.Vertex]bool {
|
func (g IG) Vertices() map[config.Vertex]bool {
|
||||||
vr := make(map[config.Vertex]bool)
|
vr := make(map[config.Vertex]bool)
|
||||||
|
g.edgelock.RLock()
|
||||||
|
defer g.edgelock.RUnlock()
|
||||||
for k, v := range g.Vert { //copy a new list
|
for k, v := range g.Vert { //copy a new list
|
||||||
vr[k] = v
|
vr[k] = v
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user