From f82f5f9ec8f8c922121b73b9872ea9753a5bdbec Mon Sep 17 00:00:00 2001 From: Akilan Date: Wed, 25 Jan 2023 08:25:10 +0000 Subject: [PATCH 1/2] fix learning nodes --- client/clientIPTable/Iptable.go | 5 +++++ p2p/iptable.go | 1 + 2 files changed, 6 insertions(+) diff --git a/client/clientIPTable/Iptable.go b/client/clientIPTable/Iptable.go index fa8c1be..9a04de5 100644 --- a/client/clientIPTable/Iptable.go +++ b/client/clientIPTable/Iptable.go @@ -61,6 +61,11 @@ func UpdateIpTable(IpAddress string, serverPort string) error { } } + err = ipStruct.WriteIpTable() + if err != nil { + return err + } + return nil } diff --git a/p2p/iptable.go b/p2p/iptable.go index 43a978b..caaca81 100644 --- a/p2p/iptable.go +++ b/p2p/iptable.go @@ -155,6 +155,7 @@ func (table *IpAddresses) RemoveDuplicates() error { if table.IpAddress[i].NAT == "True" && table.IpAddress[i].EscapeImplementation == "None" { Exists = true } + if Exists { continue } From 256998d96475fef0814168e077f5fa66ed0354bc Mon Sep 17 00:00:00 2001 From: Akilan Date: Wed, 25 Jan 2023 20:46:58 +0000 Subject: [PATCH 2/2] added mutex to avoid race condition when writing to iptable file --- client/clientIPTable/Iptable.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/client/clientIPTable/Iptable.go b/client/clientIPTable/Iptable.go index 9a04de5..c19b522 100644 --- a/client/clientIPTable/Iptable.go +++ b/client/clientIPTable/Iptable.go @@ -10,10 +10,13 @@ import ( "mime/multipart" "net/http" "os" + "sync" ) +var mu sync.Mutex + // UpdateIpTable Does the following to update it's IP table -func UpdateIpTable(IpAddress string, serverPort string) error { +func UpdateIpTable(IpAddress string, serverPort string, wg *sync.WaitGroup) error { config, err := config.ConfigInit() if err != nil { @@ -66,6 +69,8 @@ func UpdateIpTable(IpAddress string, serverPort string) error { return err } + wg.Done() + return nil } @@ -95,6 +100,8 @@ func UpdateIpTableListClient() error { return err } + var w sync.WaitGroup + // Run loop 2 times for i := 0; i < 2; i++ { // Gets information from IP table @@ -127,11 +134,13 @@ func UpdateIpTableListClient() error { continue } + w.Add(1) if Addresses.IpAddress[j].Ipv6 != "" { - go UpdateIpTable(Addresses.IpAddress[j].Ipv6, Addresses.IpAddress[j].ServerPort) + go UpdateIpTable(Addresses.IpAddress[j].Ipv6, Addresses.IpAddress[j].ServerPort, &w) } else if Addresses.IpAddress[j].Ipv4 != currentIPV4 { - go UpdateIpTable(Addresses.IpAddress[j].Ipv4, Addresses.IpAddress[j].ServerPort) + go UpdateIpTable(Addresses.IpAddress[j].Ipv4, Addresses.IpAddress[j].ServerPort, &w) } + w.Wait() //Appends server1 IP address to variable DoNotRead DoNotRead.IpAddress = append(DoNotRead.IpAddress, Addresses.IpAddress[j])