示例#1
0
文件: relay.py 项目: nskinkel/oppy
 def getBytes(self, trimmed=False):
     """TODO"""
     ret = self.header.getBytes() + self.rheader.getBytes()
     ret += struct.pack('!B', self.reason)
     if trimmed is True:
         return ret
     else:
         return FixedLenCell.padCellBytes(ret, self.header.link_version)
示例#2
0
文件: relay.py 项目: CivBase/oppy
    def getBytes(self, trimmed=False):
        '''Construct and return the byte string represented by this cell.

        :param bool trimmed: If **True**, return the non-padded payload.
            Otherwise pad the payload with null bytes to the fixed-size
            length in use according to the Link Protocol version.
        :returns: **str** byte string represented by this cell
        '''
        ret = self.header.getBytes() + self.rheader.getBytes() + self.rpayload
        return FixedLenCell.padCellBytes(ret, self.header.link_version)
示例#3
0
文件: relay.py 项目: CivBase/oppy
    def getBytes(self, trimmed=False):
        '''Build and return the raw byte string this cell represents.

        :param bool trimmed: if **True**, do not pad payload bytes
        :returns: **str** raw bytes this cell represents
        '''
        ret = self.header.getBytes() + self.rheader.getBytes()
        ret += struct.pack('!B', self.reason)
        if trimmed is True:
            return ret
        else:
            return FixedLenCell.padCellBytes(ret, self.header.link_version)
示例#4
0
文件: relay.py 项目: CivBase/oppy
    def getBytes(self, trimmed=False):
        '''Build and return the raw byte string this cell represents.

        :param bool trimmed: If **True**, do not pad this cell's payload.
        :returns: **str** raw byte string represented by this cell
        '''
        ret = self.header.getBytes() + self.rheader.getBytes()
        ret += self.addr
        ret += self.flags
        if trimmed is True:
            return ret
        else:
            return FixedLenCell.padCellBytes(ret, self.header.link_version)
示例#5
0
文件: relay.py 项目: zyk2290/oppy
    def getBytes(self, trimmed=False):
        '''Build and return the raw byte string this cell represents.

        :param bool trimmed: if **True**, do not pad payload bytes
        :returns: **str** raw byte string this cell represents
        '''
        ret = self.header.getBytes() + self.rheader.getBytes()
        ret += struct.pack('!B', self.reason)
        ret += self.reason_data
        if trimmed is True:
            return ret
        else:
            return FixedLenCell.padCellBytes(ret, self.header.link_version)
示例#6
0
文件: relay.py 项目: zyk2290/oppy
    def getBytes(self, trimmed=False):
        '''Build and return the raw byte string this cell represents.

        :param bool trimmed: If **True**, do not pad this cell's payload.
        :returns: **str** raw byte string represented by this cell
        '''
        ret = self.header.getBytes() + self.rheader.getBytes()
        ret += self.addr
        ret += self.flags
        if trimmed is True:
            return ret
        else:
            return FixedLenCell.padCellBytes(ret, self.header.link_version)
示例#7
0
CIRC_ID = 1

# Unit tests and constants for Create2Cell

CREATE2_CMD = 10
CREATE2_NTOR_HTYPE = 2
CREATE2_NTOR_HLEN = 84
CREATE2_NTOR_HDATA_DUMMY = "\x00" * CREATE2_NTOR_HLEN

create2_bytes_good = struct.pack(
    "!HBHH{}s".format(CREATE2_NTOR_HLEN),
    CIRC_ID, CREATE2_CMD,
    CREATE2_NTOR_HTYPE, CREATE2_NTOR_HLEN, CREATE2_NTOR_HDATA_DUMMY,
)
create2_bytes_good_padded = FixedLenCell.padCellBytes(create2_bytes_good)
assert len(create2_bytes_good_padded) == 512

create2_parse_bad_htype = struct.pack(
    "!HBHH{}s".format(CREATE2_NTOR_HLEN),
    CIRC_ID, CREATE2_CMD,
    # ntor should be 2
    1, CREATE2_NTOR_HLEN, CREATE2_NTOR_HDATA_DUMMY,
)
create2_parse_bad_htype = FixedLenCell.padCellBytes(create2_parse_bad_htype)
assert len(create2_parse_bad_htype) == 512

create2_parse_bad_hlen = struct.pack(
    "!HBHH{}s".format(CREATE2_NTOR_HLEN),
    CIRC_ID, CREATE2_CMD,
    # hlen should be 84 for ntor