Cooperation/Connection.py

changeset 2285
a6fc5bda1de9
parent 1509
c0b5e693b0eb
child 2302
f29e9405c851
equal deleted inserted replaced
2284:7812fbbc7d25 2285:a6fc5bda1de9
6 """ 6 """
7 Module implementing a class representing a peer connection. 7 Module implementing a class representing a peer connection.
8 """ 8 """
9 9
10 from PyQt4.QtCore import pyqtSignal, QTimer, QTime, QByteArray 10 from PyQt4.QtCore import pyqtSignal, QTimer, QTime, QByteArray
11 from PyQt4.QtNetwork import QTcpSocket 11 from PyQt4.QtNetwork import QTcpSocket, QHostInfo
12 12
13 from E5Gui import E5MessageBox 13 from E5Gui import E5MessageBox
14 from E5Gui.E5Application import e5App 14 from E5Gui.E5Application import e5App
15 15
16 import Preferences 16 import Preferences
172 except ValueError: 172 except ValueError:
173 self.abort() 173 self.abort()
174 return 174 return
175 self.__serverPort = int(serverPort) 175 self.__serverPort = int(serverPort)
176 176
177 hostInfo = QHostInfo.fromName(self.peerAddress().toString())
177 self.__username = "{0}@{1}@{2}".format( 178 self.__username = "{0}@{1}@{2}".format(
178 user, 179 user,
179 self.peerAddress().toString(), 180 hostInfo.hostName(),
180 self.peerPort() 181 self.peerPort()
181 ) 182 )
182 self.__currentDataType = Connection.Undefined 183 self.__currentDataType = Connection.Undefined
183 self.__numBytesForCurrentDataType = 0 184 self.__numBytesForCurrentDataType = 0
184 self.__buffer.clear() 185 self.__buffer.clear()
187 self.abort() 188 self.abort()
188 return 189 return
189 190
190 bannedName = "{0}@{1}".format( 191 bannedName = "{0}@{1}".format(
191 user, 192 user,
192 self.peerAddress().toString() 193 hostInfo.hostName(),
193 ) 194 )
194 Preferences.syncPreferences() 195 Preferences.syncPreferences()
195 if bannedName in Preferences.getCooperation("BannedUsers"): 196 if bannedName in Preferences.getCooperation("BannedUsers"):
196 self.rejected.emit( 197 self.rejected.emit(
197 self.trUtf8("* Connection attempted by banned user '{0}'.")\ 198 self.trUtf8("* Connection attempted by banned user '{0}'.")\
205 # if we shall accept automatically 206 # if we shall accept automatically
206 res = E5MessageBox.yesNo(None, 207 res = E5MessageBox.yesNo(None,
207 self.trUtf8("New Connection"), 208 self.trUtf8("New Connection"),
208 self.trUtf8("""<p>Accept connection from """ 209 self.trUtf8("""<p>Accept connection from """
209 """<strong>{0}@{1}</strong>?</p>""").format( 210 """<strong>{0}@{1}</strong>?</p>""").format(
210 user, self.peerAddress().toString()), 211 user, hostInfo.hostName()),
211 yesDefault=True) 212 yesDefault=True)
212 if not res: 213 if not res:
213 self.abort() 214 self.abort()
214 return 215 return
215 216

eric ide

mercurial