~ubuntu-branches/ubuntu/hardy/pymsn/hardy-proposed

« back to all changes in this revision

Viewing changes to pymsn/msnp2p/transport/switchboard.py

  • Committer: Bazaar Package Importer
  • Author(s): Laurent Bigonville, Sjoerd Simons, Laurent Bigonville, Jonny Lamb
  • Date: 2008-01-17 18:23:14 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080117182314-lwymmpnk2ut3rvr1
Tags: 0.3.1-0ubuntu1
[ Sjoerd Simons ]
* debian/rules: remove dh_python, it's no longer needed

[ Laurent Bigonville ]
* New upstream release (0.3.1)
* debian/control:
  - Add myself as an Uploaders
  - Add python:Provides for binary package
  - Add python-ctypes and python-crypto to build-deps/deps
* debian/rules: remove binary-install rule
* Add watch file
* remove pycompat file, not needed anymore
* Modify Maintainer value to match the DebianMaintainerField
  specification.

[ Jonny Lamb ]
* Added python-adns to build-deps/deps.
* Added python-pyopenssl to build-deps/deps.
* Updated copyright.
* Upped Standards-Version to 3.7.3.
* Added "XS-Dm-Upload-Allowed: yes" under the request of Sjoerd Simons.
* Added myself to Uploaders.
* Added Homepage to control.
* Added Vcs-Bzr to control.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
#
 
3
# pymsn - a python client library for Msn
 
4
#
 
5
# Copyright (C) 2007 Ali Sabil <asabil@gmail.com>
 
6
#
 
7
# This program is free software; you can redistribute it and/or modify
 
8
# it under the terms of the GNU General Public License as published by
 
9
# the Free Software Foundation; either version 2 of the License, or
 
10
# (at your option) any later version.
 
11
#
 
12
# This program is distributed in the hope that it will be useful,
 
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
# GNU General Public License for more details.
 
16
#
 
17
# You should have received a copy of the GNU General Public License
 
18
# along with this program; if not, write to the Free Software
 
19
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
20
 
 
21
from pymsn.msnp.message import MessageAcknowledgement
 
22
from pymsn.msnp2p.transport.TLP import MessageChunk
 
23
from pymsn.msnp2p.transport.base import BaseP2PTransport
 
24
from pymsn.switchboard_manager import SwitchboardClient
 
25
 
 
26
import gobject
 
27
import struct
 
28
import logging
 
29
 
 
30
__all__ = ['SwitchboardP2PTransport']
 
31
 
 
32
logger = logging.getLogger('msnp2p:transport')
 
33
 
 
34
 
 
35
class SwitchboardP2PTransport(BaseP2PTransport, SwitchboardClient):
 
36
    def __init__(self, client, contacts, transport_manager):
 
37
        SwitchboardClient.__init__(self, client, contacts)
 
38
        BaseP2PTransport.__init__(self, transport_manager, "switchboard")
 
39
 
 
40
    def close(self):
 
41
        BaseP2PTransport.close(self)
 
42
        self._leave()
 
43
 
 
44
    @staticmethod
 
45
    def _can_handle_message(message, switchboard_client=None):
 
46
        content_type = message.content_type[0]
 
47
        return content_type == 'application/x-msnmsgrp2p'
 
48
 
 
49
    @property
 
50
    def peer(self):
 
51
        for peer in self.total_participants:
 
52
            return peer
 
53
        return None
 
54
 
 
55
    @property
 
56
    def rating(self):
 
57
        return 0
 
58
 
 
59
    @property
 
60
    def max_chunk_size(self):
 
61
        return 1250 # length of the chunk including the header but not the footer
 
62
 
 
63
    def _send_chunk(self, chunk):
 
64
        headers = {'P2P-Dest': self.peer.account}
 
65
        content_type = 'application/x-msnmsgrp2p'
 
66
        body = str(chunk) + struct.pack('>L', chunk.application_id)
 
67
        self._send_message(content_type, body, headers, MessageAcknowledgement.MSNC)
 
68
 
 
69
    def _on_message_received(self, message):
 
70
        chunk = MessageChunk.parse(message.body[:-4])
 
71
        chunk.application_id = struct.unpack('>L', message.body[-4:])[0]
 
72
        self._on_chunk_received(chunk)
 
73
 
 
74
    def _on_message_sent(self, message):
 
75
        chunk = MessageChunk.parse(message.body[:-4])
 
76
        chunk.application_id = struct.unpack('>L', message.body[-4:])[0]
 
77
        self._on_chunk_sent(chunk)
 
78
 
 
79
    def _on_contact_joined(self, contact):
 
80
        pass
 
81
 
 
82
    def _on_contact_left(self, contact):
 
83
        self.close()
 
84