From 280091f7b128d56ff65820c1fd14b4ca4753b9fa Mon Sep 17 00:00:00 2001 From: Akilan Date: Tue, 24 Jan 2023 22:27:18 +0000 Subject: [PATCH] improved version of IPTable --- p2p/ip_table.json | 1 + p2p/iptable.go | 11 +++++++---- server/server.go | 7 ++++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/p2p/ip_table.json b/p2p/ip_table.json index bb1b3f4..d2ea19c 100644 --- a/p2p/ip_table.json +++ b/p2p/ip_table.json @@ -1,6 +1,7 @@ { "ip_address": [ { + "Name": "Node1", "IPV4": "64.227.168.102", "IPV6": "", "Latency": 0, diff --git a/p2p/iptable.go b/p2p/iptable.go index 2438b23..43a978b 100644 --- a/p2p/iptable.go +++ b/p2p/iptable.go @@ -123,8 +123,8 @@ func PrintIpTable() error { } for i := 0; i < len(table.IpAddress); i++ { - fmt.Printf("\nIP Address: %s\nIPV6: %s\nLatency: %s\nServerPort: %s\nbehindNAT: %s\nEscapeImplementation: %s\n-----------"+ - "-----------------\n", table.IpAddress[i].Ipv4, table.IpAddress[i].Ipv6, + fmt.Printf("\nMachine Name: %s\nIP Address: %s\nIPV6: %s\nLatency: %s\nServerPort: %s\nbehindNAT: %s\nEscapeImplementation: %s\n-----------"+ + "-----------------\n", table.IpAddress[i].Name, table.IpAddress[i].Ipv4, table.IpAddress[i].Ipv6, table.IpAddress[i].Latency, table.IpAddress[i].ServerPort, table.IpAddress[i].NAT, table.IpAddress[i].EscapeImplementation) } //PrettyPrint(table) @@ -146,12 +146,15 @@ func (table *IpAddresses) RemoveDuplicates() error { // - Node is behind NAT and no escape implementation provided if (NoDuplicates.IpAddress[k].Ipv4 != "" && NoDuplicates.IpAddress[k].Ipv4 == table.IpAddress[i].Ipv4 && NoDuplicates.IpAddress[k].ServerPort == table.IpAddress[i].ServerPort) || - (NoDuplicates.IpAddress[k].Ipv6 != "" && NoDuplicates.IpAddress[k].Ipv6 == table.IpAddress[i].Ipv6) || - (NoDuplicates.IpAddress[k].NAT == "True" && NoDuplicates.IpAddress[i].EscapeImplementation == "None") { + (NoDuplicates.IpAddress[k].Ipv6 != "" && NoDuplicates.IpAddress[k].Ipv6 == table.IpAddress[i].Ipv6) { Exists = true break } } + + if table.IpAddress[i].NAT == "True" && table.IpAddress[i].EscapeImplementation == "None" { + Exists = true + } if Exists { continue } diff --git a/server/server.go b/server/server.go index 06b495e..df71181 100644 --- a/server/server.go +++ b/server/server.go @@ -166,9 +166,9 @@ func Server() error { // If there is a proxy port specified // then starts the FRP server - if config.FRPServerPort != "0" { - go frp.StartFRPProxyFromRandom() - } + //if config.FRPServerPort != "0" { + // go frp.StartFRPProxyFromRandom() + //} // TODO check if IPV6 or Proxy port is specified // if not update current entry as proxy address @@ -210,6 +210,7 @@ func Server() error { ProxyIpAddr.Ipv4 = lowestLatencyIpAddress.Ipv4 ProxyIpAddr.ServerPort = proxyPort ProxyIpAddr.Name = config.MachineName + ProxyIpAddr.NAT = "False" ProxyIpAddr.EscapeImplementation = "FRP" // append the following to the ip table