PINGSPEED = 50.0
-DEBUGALL = False
+DEBUGALL = True
LINEDEBUG = False
MESSAGEDEBUG = False
MSNP2PDEBUG = False
if not message.getHeader("P2P-Dest") == self.userHandle: return
packet = message.message
binaryFields = BinaryFields(packet=packet)
- if binaryFields[0] != 0:
+ if binaryFields[5] == BinaryFields.BYEGOT:
+ pass # Ignore the ACKs to SLP messages
+ elif binaryFields[0] != 0:
slpLink = self.slpLinks.get(binaryFields[0])
if not slpLink:
# Link has been killed. Ignore
return
if slpLink.remoteUser == message.userHandle:
slpLink.handlePacket(packet)
- if binaryFields[5] == BinaryFields.ACK or binaryFields[5] == BinaryFields.BYEGOT:
+ elif binaryFields[5] == BinaryFields.ACK:
pass # Ignore the ACKs to SLP messages
else:
slpMessage = MSNSLPMessage(packet)
self.seqID = SeqID()
def killLink(self):
+ if MSNP2PDEBUG: log.msg("killLink")
def kill():
+ if MSNP2PDEBUG: log.msg("killLink - kill()")
if not self.switchboard: return
del self.switchboard.slpLinks[self.sessionID]
self.switchboard = None
else:
if slpMessage.status == "603":
self.acceptDeferred.callback((False,))
- # SLPLink is over due to decline, error or BYE
+ if MSNP2PDEBUG: log.msg("SLPLink is over due to decline, error or BYE")
self.killLink()
def wait_data_ack(self, packet):
self.handlePacket = lambda packet: None
def handleSLPMessage(self, slpMessage):
- self.killLink() # BYE or error
+ if MSNP2PDEBUG: log.msg("BYE or error")
+ self.killLink()
def close(self):
SLPLink_Send.close(self)
FileReceive.accept(self, consumer)
if not self.switchboard: return
self.sendSLPMessage("200", "application/x-msnmsgr-sessionreqbody", {"SessionID":self.sessionID}, branch=self.initialBranch)
+ self.handlePacket = self.wait_data # Moved here because sometimes the second INVITE seems to be skipped
def handleSLPMessage(self, slpMessage):
if slpMessage.method == "INVITE": # The second invite
"Listening" : "false",\
"Hashed-Nonce": "{00000000-0000-0000-0000-000000000000}"}
self.sendSLPMessage("200", "application/x-msnmsgr-transrespbody", data, branch=slpMessage.branch)
- self.handlePacket = self.wait_data
+# self.handlePacket = self.wait_data # Moved up
else:
- self.killLink() # It's either a BYE or an error
+ if MSNP2PDEBUG: log.msg("It's either a BYE or an error")
+ self.killLink()
# FIXME, do some error handling if it was an error
def doFinished(self):
if slpMessage.status == "200":
self.handlePacket = self.wait_dataprep
else:
- # SLPLink is over due to error or BYE
+ if MSNP2PDEBUG: log.msg("SLPLink is over due to error or BYE")
self.killLink()
def doFinished(self):
# Copyright (c) 2001-2005 Twisted Matrix Laboratories.
-# Copyright (c) 2005 James Bunton
+# Copyright (c) 2005-2006 James Bunton
# See LICENSE for details.
"""
Test cases for msn.
"""
+# Settings
+LOGGING = False
+
+
+
+
# Twisted imports
from twisted.protocols import loopback
from twisted.protocols.basic import LineReceiver
from twisted.internet.defer import Deferred
from twisted.internet import reactor, main
-from twisted.python import failure
+from twisted.python import failure, log
from twisted.trial import unittest
# System imports
import msn
+if LOGGING:
+ log.startLogging(sys.stdout)
+
def printError(f):
print f
-# Copyright 2005 James Bunton <james@delx.cjb.net>
+# Copyright 2005-2006 James Bunton <james@delx.cjb.net>
# Licensed for distribution under the GPL version 2, check COPYING for details
"""
Test cases for msnw (MSN Wrapper)
"""
+# Settings
+TIMEOUT = 30.0 # Connection timeout in seconds
+LOGGING = True
+TWOFILES = False
+FTSENDTEST = False
+FTRECEIVETEST = False
+USER1 = "messengertest1@hotmail.com"
+PASS1 = "hellohello"
+USER2 = "messengertest2@hotmail.com"
+PASS2 = "hellohello"
+
+
+
# Twisted imports
from twisted.internet.defer import Deferred
from twisted.internet import reactor, error
import msn
-# Settings
-TIMEOUT = 30.0 # Connection timeout in seconds
-LOGGING = True
-USER1 = "messengertest1@hotmail.com"
-PASS1 = "hellohello"
-USER2 = "messengertest2@hotmail.com"
-PASS2 = "hellohello"
-
-
-
if LOGGING:
log.startLogging(sys.stdout)
def testConnect(self):
self.doLogins(both=False)
-# testConnect.skip = "True"
+ testConnect.skip = FTRECEIVETEST or FTSENDTEST
def testPurgeContacts(self):
self.doLogins()
self.doPurgeContacts()
-# testPurgeContacts.skip = "True"
+ testPurgeContacts.skip = FTRECEIVETEST or FTSENDTEST
def testAddContacts(self):
self.doLogins()
self.doPurgeContacts()
self.doAddContacts()
-# testAddContacts.skip = "True"
+ testAddContacts.skip = FTRECEIVETEST or FTSENDTEST
def testMessageExchange(self):
self.doLogins()
self.user1.sendMessage(USER2, "Hi user2")
self.loop("Timeout exchanging message.", cond="GOTMESSAGE")
self.failUnless((self.user2.message == (USER1, "Hi user2")), "Failed to transfer message.")
-# testMessageExchange.skip = "True"
+ testMessageExchange.skip = FTRECEIVETEST or FTSENDTEST
def testFileSend(self):
if raw_input("\n\nALERT!!!\n\nPlease connect to account %s and accept the file transfer from %s. When you have received the complete file, send a message back to the client to signal success.\nType ok when you are ready: " % (USER2, USER1)).lower() != "ok":
d = self.user1.sendFile(USER2, "myfile.txt", len(data))
d.addCallback(gotFileSend)
self.loop("Sending file.", cond="GOTMESSAGE", timeout=60*60)
- testFileSend.skip = "True"
+ global TWOFILES
+ if TWOFILES:
+ d = self.user1.sendFile(USER2, "myfile2.txt", len(data))
+ d.addCallback(gotFileSend)
+ self.loop("Sending file.", cond="GOTMESSAGE", timeout=60*60)
+ testFileSend.skip = not FTSENDTEST
def testFileReceive(self):
if raw_input("\n\nALERT!!!\n\nPlease connect to account %s and send a file transfer to %s.\nType ok when you are ready: " % (USER2, USER1)).lower() != "ok":
self.doPurgeContacts(both=False)
self.doAddContacts(both=False)
self.loop("Receiving file.", cond="GOTFILE", timeout=60*60)
- testFileReceive.skip = "True"
+ global TWOFILES
+ if TWOFILES:
+ self.loop("Receiving file.", cond="GOTFILE", timeout=60*60)
+ testFileReceive.skip = not FTRECEIVETEST