Esempio n. 1
0
 def send_command(self, action, data=''):
     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     try:
         s.connect(('127.0.0.1', 56881))
         s.send(tobinary(len(action)))
         s.send(action)
         s.send(tobinary(len(data)))
         s.send(data)
         s.close()
     except socket.error, e:
         s.close()
         raise BTFailure('Could not send command: ' + str(e))
Esempio n. 2
0
 def send_command(self, action, data=''):
     s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
     filename = self.socket_filename
     try:
         s.connect(filename)
         s.send(tobinary(len(action)))
         s.send(action)
         s.send(tobinary(len(data)))
         s.send(data)
         s.close()
     except socket.error, e:
         s.close()
         raise BTFailure('Could not send command: ' + str(e))
Esempio n. 3
0
 def send_piece(self, index, begin, piece):
     msg = "".join([tobinary(index), tobinary(begin), piece])
     self.transfer_ctl_msg(PIECE, msg)
Esempio n. 4
0
 def send_have(self, index):
     self.transfer_ctl_msg(HAVE, tobinary(index))
Esempio n. 5
0
 def send_cancel(self, index, begin, length):
     self.transfer_ctl_msg(CANCEL, tobinary(index) +
         tobinary(begin) + tobinary(length))
Esempio n. 6
0
 def send_request(self, index, begin, length):
     self.transfer_ctl_msg(REQUEST, tobinary(index) +
         tobinary(begin) + tobinary(length))
Esempio n. 7
0
 def mk_partial(self, message):
     fmt = PARTIAL + tobinary(len(message))
     self._deeplen += PARTIAL_FMT_LEN
     return fmt + message
Esempio n. 8
0
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Written by John Schanck and Rich Jones

# PartialMessageQueue is used by NeighborLink to queue
# partial messages sent by EndPoints. The partial messages
# must be queued so that EndPoints do not accidentally insert
# file chunks into the streams of other EndPoints communicating
# on the same NeighborLink. PartialMessageQueue also holds the id
# of the stream which sent each message in the queue, so that the
# stream can be notified when the message is dequeued for sending.

from Anomos.Protocol import tobinary, PARTIAL

PARTIAL_FMT_LEN = len(PARTIAL + tobinary(0))


class PartialMessageQueue(object):
    #TODO: Give this a maximum length.
    def __init__(self):
        self._deeplen = 0
        self.msgs = {}

    def queue_message(self, sid, message):
        """ Add a message to the message queue 
            @param streamid: Stream ID of message sender
            @param message: Message to be sent
            @type streamid: int
            @type message: string"""
        self._deeplen += len(message)
Esempio n. 9
0
 def mk_partial(self, message):
     fmt = PARTIAL + tobinary(len(message))
     self._deeplen += PARTIAL_FMT_LEN
     return fmt + message
Esempio n. 10
0
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Written by John Schanck and Rich Jones

# PartialMessageQueue is used by NeighborLink to queue
# partial messages sent by EndPoints. The partial messages
# must be queued so that EndPoints do not accidentally insert
# file chunks into the streams of other EndPoints communicating
# on the same NeighborLink. PartialMessageQueue also holds the id
# of the stream which sent each message in the queue, so that the
# stream can be notified when the message is dequeued for sending.

from Anomos.Protocol import tobinary, PARTIAL

PARTIAL_FMT_LEN = len(PARTIAL+tobinary(0))

class PartialMessageQueue(object):
    #TODO: Give this a maximum length.
    def __init__(self):
        self._deeplen = 0
        self.msgs = {}
    def queue_message(self, sid, message):
        """ Add a message to the message queue 
            @param streamid: Stream ID of message sender
            @param message: Message to be sent
            @type streamid: int
            @type message: string"""
        self._deeplen += len(message)
        self.msgs.setdefault(sid, []).append(message)
    def is_partial(self, message):
Esempio n. 11
0
 def format_message(self, stream_id, message):
     return tobinary(stream_id)[2:] + \
            tobinary(len(message)) + message