From 37979b4f9cbc3e3eb99cc8560edb72c3033cc558 Mon Sep 17 00:00:00 2001
From: shortcutme <tamas@zeronet.io>
Date: Thu, 24 Jan 2019 15:20:08 +0100
Subject: [PATCH] Support multiple external ips

---
 plugins/AnnounceShare/AnnounceSharePlugin.py | 5 +++--
 plugins/Sidebar/SidebarPlugin.py             | 9 +++++----
 src/Config.py                                | 2 +-
 src/File/FileServer.py                       | 5 +++--
 4 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/plugins/AnnounceShare/AnnounceSharePlugin.py b/plugins/AnnounceShare/AnnounceSharePlugin.py
index fbc451b7..95f1fa74 100644
--- a/plugins/AnnounceShare/AnnounceSharePlugin.py
+++ b/plugins/AnnounceShare/AnnounceSharePlugin.py
@@ -173,8 +173,9 @@ class FileServerPlugin(object):
     def portCheck(self, *args, **kwargs):
         res = super(FileServerPlugin, self).portCheck(*args, **kwargs)
         if res and not config.tor == "always" and "Bootstrapper" in PluginManager.plugin_manager.plugin_names:
-            my_tracker_address = "zero://%s:%s" % (config.ip_external, config.fileserver_port)
-            tracker_storage.onTrackerFound(my_tracker_address, my=True)
+            for ip in config.ip_external:
+                my_tracker_address = "zero://%s:%s" % (ip, config.fileserver_port)
+                tracker_storage.onTrackerFound(my_tracker_address, my=True)
         return res
 
 
diff --git a/plugins/Sidebar/SidebarPlugin.py b/plugins/Sidebar/SidebarPlugin.py
index 4aa8f4b3..1b4fadec 100644
--- a/plugins/Sidebar/SidebarPlugin.py
+++ b/plugins/Sidebar/SidebarPlugin.py
@@ -667,10 +667,11 @@ class UiWebsocketPlugin(object):
             peer_locations.append(peer_location)
 
         # Append myself
-        my_loc = self.getLoc(geodb, config.ip_external)
-        if my_loc:
-            my_loc["ping"] = 0
-            peer_locations.append(my_loc)
+        for ip in config.ip_external:
+            my_loc = self.getLoc(geodb, ip)
+            if my_loc:
+                my_loc["ping"] = 0
+                peer_locations.append(my_loc)
 
         return peer_locations
 
diff --git a/src/Config.py b/src/Config.py
index cb672bc6..f239bdbc 100644
--- a/src/Config.py
+++ b/src/Config.py
@@ -243,7 +243,7 @@ class Config(object):
         self.parser.add_argument('--disable_udp', help='Disable UDP connections', action='store_true')
         self.parser.add_argument('--proxy', help='Socks proxy address', metavar='ip:port')
         self.parser.add_argument('--bind', help='Bind outgoing sockets to this address', metavar='ip')
-        self.parser.add_argument('--ip_external', help='Set reported external ip (tested on start if None)', metavar='ip')
+        self.parser.add_argument('--ip_external', help='Set reported external ip (tested on start if None)', metavar='ip', nargs='*')
         self.parser.add_argument('--trackers', help='Bootstraping torrent trackers', default=trackers, metavar='protocol://address', nargs='*')
         self.parser.add_argument('--trackers_file', help='Load torrent trackers dynamically from a file', default=False, metavar='path')
         self.parser.add_argument('--trackers_proxy', help='Force use proxy to connect to trackers (disable, tor, ip:port)', default="disable")
diff --git a/src/File/FileServer.py b/src/File/FileServer.py
index f10394a8..fa370dce 100644
--- a/src/File/FileServer.py
+++ b/src/File/FileServer.py
@@ -63,8 +63,9 @@ class FileServer(ConnectionServer):
         self.port_opened = {}
 
         if config.ip_external:  # Ip external defined in arguments
-            self.port_opened[helper.getIpType(config.ip_external)] = True
-            SiteManager.peer_blacklist.append((config.ip_external, self.port))  # Add myself to peer blacklist
+            for ip_external in config.ip_external:
+                self.port_opened[helper.getIpType(ip_external)] = True
+                SiteManager.peer_blacklist.append((ip_external, self.port))  # Add myself to peer blacklist
 
         self.sites = {}
         self.last_request = time.time()