(self)
| 124 | self.udpSockets[udpSocket.listening.host] = udpSocket |
| 125 | |
| 126 | def loop(self): |
| 127 | # defaults to empty loop if outbound connections are maxed |
| 128 | spawnConnections = False |
| 129 | acceptConnections = True |
| 130 | if BMConfigParser().safeGetBoolean('bitmessagesettings', 'dontconnect'): |
| 131 | acceptConnections = False |
| 132 | elif BMConfigParser().safeGetBoolean('bitmessagesettings', 'sendoutgoingconnections'): |
| 133 | spawnConnections = True |
| 134 | if BMConfigParser().get('bitmessagesettings', 'socksproxytype')[0:5] == 'SOCKS' and \ |
| 135 | (not BMConfigParser().getboolean('bitmessagesettings', 'sockslisten') and \ |
| 136 | ".onion" not in BMConfigParser().get('bitmessagesettings', 'onionhostname')): |
| 137 | acceptConnections = False |
| 138 | |
| 139 | if spawnConnections: |
| 140 | if not self.bootstrapped: |
| 141 | helper_bootstrap.dns() |
| 142 | self.bootstrapped = True |
| 143 | Proxy.proxy = (BMConfigParser().safeGet("bitmessagesettings", "sockshostname"), |
| 144 | BMConfigParser().safeGetInt("bitmessagesettings", "socksport")) |
| 145 | # TODO AUTH |
| 146 | # TODO reset based on GUI settings changes |
| 147 | try: |
| 148 | if not BMConfigParser().get("network", "onionsocksproxytype").startswith("SOCKS"): |
| 149 | raise NoOptionError |
| 150 | Proxy.onionproxy = (BMConfigParser().get("network", "onionsockshostname"), |
| 151 | BMConfigParser().getint("network", "onionsocksport")) |
| 152 | except (NoOptionError, NoSectionError): |
| 153 | Proxy.onionproxy = None |
| 154 | established = sum(1 for c in self.outboundConnections.values() if (c.connected and c.fullyEstablished)) |
| 155 | pending = len(self.outboundConnections) - established |
| 156 | if established < BMConfigParser().safeGetInt("bitmessagesettings", "maxoutboundconnections"): |
| 157 | for i in range(state.maximumNumberOfHalfOpenConnections - pending): |
| 158 | try: |
| 159 | chosen = chooseConnection(random.choice(self.streams)) |
| 160 | except ValueError: |
| 161 | continue |
| 162 | if chosen in self.outboundConnections: |
| 163 | continue |
| 164 | if chosen.host in self.inboundConnections: |
| 165 | continue |
| 166 | # don't connect to self |
| 167 | if chosen in state.ownAddresses: |
| 168 | continue |
| 169 | |
| 170 | #for c in self.outboundConnections: |
| 171 | # if chosen == c.destination: |
| 172 | # continue |
| 173 | #for c in self.inboundConnections: |
| 174 | # if chosen.host == c.destination.host: |
| 175 | # continue |
| 176 | try: |
| 177 | if chosen.host.endswith(".onion") and Proxy.onionproxy is not None: |
| 178 | if BMConfigParser().get("network", "onionsocksproxytype") == "SOCKS5": |
| 179 | self.addConnection(Socks5BMConnection(chosen)) |
| 180 | elif BMConfigParser().get("network", "onionsocksproxytype") == "SOCKS4a": |
| 181 | self.addConnection(Socks4aBMConnection(chosen)) |
| 182 | elif BMConfigParser().safeGet("bitmessagesettings", "socksproxytype") == "SOCKS5": |
| 183 | self.addConnection(Socks5BMConnection(chosen)) |
no test coverage detected