(self, connection=None)
| 68 | |
| 69 | # Connect to host |
| 70 | def connect(self, connection=None): |
| 71 | if self.reputation < -10: |
| 72 | self.reputation = -10 |
| 73 | if self.reputation > 10: |
| 74 | self.reputation = 10 |
| 75 | |
| 76 | if self.connection: |
| 77 | self.log("Getting connection (Closing %s)..." % self.connection) |
| 78 | self.connection.close("Connection change") |
| 79 | else: |
| 80 | self.log("Getting connection (reputation: %s)..." % self.reputation) |
| 81 | |
| 82 | if connection: # Connection specified |
| 83 | self.log("Assigning connection %s" % connection) |
| 84 | self.connection = connection |
| 85 | self.connection.sites += 1 |
| 86 | else: # Try to find from connection pool or create new connection |
| 87 | self.connection = None |
| 88 | |
| 89 | try: |
| 90 | if self.connection_server: |
| 91 | connection_server = self.connection_server |
| 92 | elif self.site: |
| 93 | connection_server = self.site.connection_server |
| 94 | else: |
| 95 | import main |
| 96 | connection_server = main.file_server |
| 97 | self.connection = connection_server.getConnection(self.ip, self.port, site=self.site, is_tracker_connection=self.is_tracker_connection) |
| 98 | self.reputation += 1 |
| 99 | self.connection.sites += 1 |
| 100 | except Exception as err: |
| 101 | self.onConnectionError("Getting connection error") |
| 102 | self.log("Getting connection error: %s (connection_error: %s, hash_failed: %s)" % |
| 103 | (Debug.formatException(err), self.connection_error, self.hash_failed)) |
| 104 | self.connection = None |
| 105 | return self.connection |
| 106 | |
| 107 | # Check if we have connection to peer |
| 108 | def findConnection(self): |
no test coverage detected