except KeyError:
log.msg('Received munged file transfer request ... ignoring.')
return 0
- import msnft
+ raise NotImplementedError
self.gotSendRequest(msnft.MSNFTP_Receive(filename, filesize, message.userHandle, cookie, connectivity, self))
return 1
def _handleP2PMessage(self, message):
""" helper method for msnslp messages (file transfer & avatars) """
+ if not message.getHeader("P2P-Dest") == self.userHandle: return
packet = message.message
binaryFields = BinaryFields(packet=packet)
if binaryFields[0] != 0:
FileReceive.__init__(self, filename, filesize, remoteUser)
def reject(self):
- pass
+ # Send a 603 decline
+ self.sendMSNSLPResponse("603 Decline")
+ self.killLink()
def accept(self, consumer):
FileReceive.accept(self, consumer)
# Check that client2 got the avatar
self.failUnless((self.gotAvatar), "Failed to transfer avatar")
- def testFiles(self):
+ def testFilesHappyPath(self):
fileData = self._generateData()
self.gotFile = False
self.gotFile = (data == fileData)
fileBuffer = msn.StringBuffer(finished)
fileReceive = self.client1.fileReceive
+ self.failUnless((fileReceive.filename == "myfile.txt" and fileReceive.filesize == len(fileData)), "Filename or length wrong.")
fileReceive.accept(fileBuffer)
# Lets transfer!!
- self._loop(100)
+ self._loop(10)
self.failUnless((self.gotFile), "Failed to transfer file")
+ def testFilesDeclinePath(self):
+ fileData = self._generateData()
+ self.gotDecline = False
+
+ # Send the file (client2->client1)
+ msnContact = msn.MSNContact(userHandle='foo1@bar.com', caps=msn.MSNContact.MSNC1)
+ fileSend, d = self.client2.sendFile(msnContact, "myfile.txt", len(fileData))
+ def accepted((yes,)):
+ self.failUnless((not yes), "Failed to understand a decline.")
+ self.gotDecline = True
+ def failed():
+ raise "TransferError"
+ d.addCallback(accepted)
+ d.addErrback(failed)
+
+ # Let the request get pushed to client1
+ self._loop(10)
+
+ # Decline the file
+ fileReceive = self.client1.fileReceive
+ fileReceive.reject()
+
+ # Let the decline get pushed to client2
+ self._loop(10)
+
+ self.failUnless((self.gotDecline), "Failed to understand a decline, ignored.")
+
################
# MSNFTP tests #