diff --git a/AnnounceBitTorrent/AnnounceBitTorrentPlugin.py b/AnnounceBitTorrent/AnnounceBitTorrentPlugin.py index fab7bb1..628bc31 100644 --- a/AnnounceBitTorrent/AnnounceBitTorrentPlugin.py +++ b/AnnounceBitTorrent/AnnounceBitTorrentPlugin.py @@ -82,7 +82,10 @@ def httpRequest(self, url): req = urllib.request.Request(url, headers=headers) - if config.trackers_proxy == "tor": + if ".i2p" in url: + i2p_manager = self.site.connection_server.i2p_manager + return i2p_manager.urlopen(self.site.address, req, timeout=50) + elif config.trackers_proxy == "tor": tor_manager = self.site.connection_server.tor_manager handler = sockshandler.SocksiPyHandler(socks.SOCKS5, tor_manager.proxy_ip, tor_manager.proxy_port) opener = urllib.request.build_opener(handler) diff --git a/AnnounceZero/AnnounceZeroPlugin.py b/AnnounceZero/AnnounceZeroPlugin.py index a01c73e..5de3d11 100644 --- a/AnnounceZero/AnnounceZeroPlugin.py +++ b/AnnounceZero/AnnounceZeroPlugin.py @@ -31,6 +31,14 @@ def processPeerRes(tracker_address, site, peers): if site.addPeer(peer_onion, peer_port, source="tracker"): added += 1 + # I2P Destinations + found_dest = 0 + for packed_address in peers["i2p"]: + found_dest += 1 + peer_dest, peer_port = helper.unpackI2PAddress(packed_address) + if site.addPeer(peer_dest, peer_port): + added += 1 + # Ip4 found_ipv4 = 0 peers_normal = itertools.chain(peers.get("ip4", []), peers.get("ipv4", []), peers.get("ipv6", [])) @@ -62,6 +70,8 @@ def announceTrackerZero(self, tracker_address, mode="start", num_want=10): need_types += self.site.connection_server.supported_ip_types if self.site.connection_server.tor_manager.enabled: need_types.append("onion") + if self.site.connection_server.i2p_manager.enabled: + need_types.append("i2p") if mode == "start" or mode == "more": # Single: Announce only this site sites = [self.site] @@ -77,12 +87,15 @@ def announceTrackerZero(self, tracker_address, mode="start", num_want=10): # Create request add_types = self.getOpenedServiceTypes() request = { - "hashes": [], "onions": [], "port": self.fileserver_port, "need_types": need_types, "need_num": 20, "add": add_types + "hashes": [], "onions": [], "i2pdests": [], "port": self.fileserver_port, "need_types": need_types, "need_num": 20, "add": add_types } for site in sites: if "onion" in add_types: onion = self.site.connection_server.tor_manager.getOnion(site.address) request["onions"].append(onion) + if "i2p" in add_types: + dest = self.site.connection_server.i2p_manager.getDest(site.address) + request["i2pdests"].append(dest.base64()) request["hashes"].append(site.address_hash) # Tracker can remove sites that we don't announce @@ -130,6 +143,21 @@ def announceTrackerZero(self, tracker_address, mode="start", num_want=10): time_full_announced[tracker_address] = 0 raise AnnounceError("Announce onion address to failed: %s" % res) + if "i2p_sign_this" in res: + self.site.log.debug("Signing %s for %s to add %s I2P dests" % (res["i2p_sign_this"], tracker_address, len(sites))) + request["i2p_signs"] = {} + request["i2p_sign_this"] = res["i2p_sign_this"] + request["need_num"] = 0 + for site in sites: + dest = self.connection_server.i2p_manager.getPrivateDest(site.address) + sign = dest.sign(res["i2p_sign_this"]) + request["i2p_signs"][dest.base64()] = sign + res = tracker.request("announce", request) + if not res or "i2p_sign_this" in res: + if full_announce: + time_full_announced[tracker_address] = 0 + raise AnnounceError("Announce I2P Destination to %s failed: %s" % (tracker_address, res)) + if full_announce: tracker_peer.remove() # Close connection, we don't need it in next 5 minute diff --git a/Sidebar/SidebarPlugin.py b/Sidebar/SidebarPlugin.py index b382304..27f0837 100644 --- a/Sidebar/SidebarPlugin.py +++ b/Sidebar/SidebarPlugin.py @@ -91,6 +91,7 @@ def sidebarRenderPeerStats(self, body, site): connected = len([peer for peer in list(site.peers.values()) if peer.connection and peer.connection.connected]) connectable = len([peer_id for peer_id in list(site.peers.keys()) if not peer_id.endswith(":0")]) onion = len([peer_id for peer_id in list(site.peers.keys()) if ".onion" in peer_id]) + i2p = len([peer_id for peer_id in list(site.peers.keys()) if ".i2p" in peer_id]) local = len([peer for peer in list(site.peers.values()) if helper.isPrivateIp(peer.ip)]) peers_total = len(site.peers) @@ -101,13 +102,16 @@ def sidebarRenderPeerStats(self, body, site): connectable += 1 if site.connection_server.tor_manager.start_onions: onion += 1 + if site.connection_server.i2p_manager.start_dests: + i2p += 1 if peers_total: percent_connected = float(connected) / peers_total percent_connectable = float(connectable) / peers_total percent_onion = float(onion) / peers_total + percent_i2p = float(i2p) / peers_total else: - percent_connectable = percent_connected = percent_onion = 0 + percent_connectable = percent_connected = percent_onion = percent_i2p = 0 if local: local_html = _("