예제 #1
0
 def pack(self, packer: Packer) -> None:
     self.data_name.pack(packer)
     if self.data_value is None:
         packer.pack_uint(0)
     else:
         packer.pack_uint(1)
         self.data_value.pack(packer)
예제 #2
0
 def pack(self, packer: Packer) -> None:
     self.num_sponsored.pack(packer)
     self.num_sponsoring.pack(packer)
     packer.pack_uint(len(self.signer_sponsoring_i_ds))
     for signer_sponsoring_i_d in self.signer_sponsoring_i_ds:
         signer_sponsoring_i_d.pack(packer)
     self.ext.pack(packer)
예제 #3
0
 def pack(self, packer: Packer) -> None:
     self.tx_set_hash.pack(packer)
     self.close_time.pack(packer)
     packer.pack_uint(len(self.upgrades))
     for upgrade in self.upgrades:
         upgrade.pack(packer)
     self.ext.pack(packer)
예제 #4
0
 def pack(self, packer: Packer) -> None:
     if self.source_account is None:
         packer.pack_uint(0)
     else:
         packer.pack_uint(1)
         self.source_account.pack(packer)
     self.body.pack(packer)
예제 #5
0
    def pack(self, values):
        metric = {
            'hostname': '',
            'spoof': 0,
            'units': '',
            'slope': 'both',
            'tmax': 60,
            'dmax': 0
        }
        metric.update(values)

        if metric.get('spoof', False):
            metric['spoof'] = 1
        else:
            metric['spoof'] = 0

        metric['slope'] = SLOPE[metric['slope']]

        for key in ('name', 'value', 'type'):
            if key not in metric:
                raise KeyError("Missing {0}".format(key))

        if metric['type'] not in ('string', 'int8', 'uint8', 'int16', 'uint16',
                                  'int32', 'uint32', 'float', 'double'):
            raise TypeError("Invalid metric type")

        convert = lambda v: v.encode() if isinstance(v, str) else v
        metric = {key: convert(value) for key, value in metric.items()}

        # Metadata
        meta = Packer()
        meta.pack_int(128)
        meta.pack_string(metric['hostname'])
        meta.pack_string(metric['name'])
        meta.pack_int(int(metric['spoof']))
        meta.pack_string(metric['type'])
        meta.pack_string(metric['name'])
        meta.pack_string(metric['units'])
        meta.pack_int(metric['slope'])
        meta.pack_uint(int(metric['tmax']))
        meta.pack_uint(int(metric['dmax']))

        # Group support
        if 'group' in metric:
            meta.pack_int(1)
            meta.pack_string(b"GROUP")
            meta.pack_string(metric['group'])
        else:
            meta.pack_int(0)

        # Data
        data = Packer()
        data.pack_int(128 + 5)
        data.pack_string(metric['hostname'])
        data.pack_string(metric['name'])
        data.pack_int(int(metric['spoof']))
        data.pack_string(b"%s")
        data.pack_string(bytes(metric['value']))

        return meta.get_buffer(), data.get_buffer()
예제 #6
0
파일: security.py 프로젝트: kofemann/pynfs
 def secure_data(self, cred, data):
     log_gss.debug("secure_data(%r)" % cred)
     cred = cred.body
     if cred.service ==  rpc_gss_svc_none or \
        cred.gss_proc in (RPCSEC_GSS_INIT, RPCSEC_GSS_CONTINUE_INIT):
         return data
     p = Packer()
     context = self._get_context(cred.handle)
     try:
         if cred.service == rpc_gss_svc_integrity:
             # data = opaque[gss_seq_num+data] + opaque[checksum]
             p.pack_uint(cred.seq_num)
             data = p.get_buffer() + data
             token = context.getMIC(data) # XXX BUG set qop
             p.reset()
             p.pack_opaque(data)
             p.pack_opaque(token)
             data = p.get_buffer()
         elif cred.service == rpc_gss_svc_privacy:
             # data = opaque[wrap([gss_seq_num+data])]
             p.pack_uint(cred.seq_num)
             data = p.get_buffer() + data
             token = context.wrap(data) # XXX BUG set qop
             p.reset()
             p.pack_opaque(token)
             data = p.get_buffer()
         else:
             # Can't get here, but doesn't hurt
             log_gss.error("Unknown service %i for RPCSEC_GSS" % cred.service)
     except gssapi.Error as e:
         # XXX What now?
         log_gss.warn("secure_data: gssapi call returned %s" % e.name)
         raise
     return data
예제 #7
0
 def pack(self, packer: Packer) -> None:
     if not self.fixed:
         size = len(self.value)
         packer.pack_uint(size)
     else:
         size = self.size
     packer.pack_fopaque(size, self.value)
예제 #8
0
파일: security.py 프로젝트: wzugang/pynfs
 def secure_data(self, cred, data):
     log_gss.debug("secure_data(%r)" % cred)
     cred = cred.body
     if cred.service ==  rpc_gss_svc_none or \
        cred.gss_proc in (RPCSEC_GSS_INIT, RPCSEC_GSS_CONTINUE_INIT):
         return data
     p = Packer()
     context = self._get_context(cred.handle)
     try:
         if cred.service == rpc_gss_svc_integrity:
             # data = opaque[gss_seq_num+data] + opaque[checksum]
             p.pack_uint(cred.seq_num)
             data = p.get_buffer() + data
             token = context.getMIC(data)  # XXX BUG set qop
             p.reset()
             p.pack_opaque(data)
             p.pack_opaque(token)
             data = p.get_buffer()
         elif cred.service == rpc_gss_svc_privacy:
             # data = opaque[wrap([gss_seq_num+data])]
             p.pack_uint(cred.seq_num)
             data = p.get_buffer() + data
             token = context.wrap(data)  # XXX BUG set qop
             p.reset()
             p.pack_opaque(token)
             data = p.get_buffer()
         else:
             # Can't get here, but doesn't hurt
             log_gss.error("Unknown service %i for RPCSEC_GSS" %
                           cred.service)
     except gssapi.Error as e:
         # XXX What now?
         log_gss.warn("secure_data: gssapi call returned %s" % e.name)
         raise
     return data
예제 #9
0
    def pack(self, values):
        metric = {
            'hostname': '',
            'spoof': 0,
            'units': '',
            'slope': 'both',
            'tmax': 60,
            'dmax': 0
        }
        metric.update(values)

        if metric.get('spoof', False):
            metric['spoof'] = 1
        else:
            metric['spoof'] = 0

        metric['slope'] = SLOPE[metric['slope']]

        for key in ('name', 'value', 'type'):
            if key not in metric:
                raise KeyError("Missing {0}".format(key))

        if metric['type'] not in ('string', 'int8', 'uint8', 'int16', 'uint16', 'int32', 'uint32', 'float', 'double'):
            raise TypeError("Invalid metric type")

        convert = lambda v: v.encode() if isinstance(v, str) else v
        metric = {key: convert(value) for key, value in metric.items()}

        # Metadata
        meta = Packer()
        meta.pack_int(128)
        meta.pack_string(metric['hostname'])
        meta.pack_string(metric['name'])
        meta.pack_int(int(metric['spoof']))
        meta.pack_string(metric['type'])
        meta.pack_string(metric['name'])
        meta.pack_string(metric['units'])
        meta.pack_int(metric['slope'])
        meta.pack_uint(int(metric['tmax']))
        meta.pack_uint(int(metric['dmax']))

        # Group support
        if 'group' in metric:
            meta.pack_int(1)
            meta.pack_string(b"GROUP")
            meta.pack_string(metric['group'])
        else:
            meta.pack_int(0)

        # Data
        data = Packer()
        data.pack_int(128 + 5)
        data.pack_string(metric['hostname'])
        data.pack_string(metric['name'])
        data.pack_int(int(metric['spoof']))
        data.pack_string(b"%s")
        data.pack_string(bytes(metric['value']))

        return meta.get_buffer(), data.get_buffer()
예제 #10
0
 def pack(self, packer: Packer) -> None:
     self.balance_id.pack(packer)
     packer.pack_uint(len(self.claimants))
     for claimant in self.claimants:
         claimant.pack(packer)
     self.asset.pack(packer)
     self.amount.pack(packer)
     self.ext.pack(packer)
예제 #11
0
 def pack(self, packer: Packer) -> None:
     self.quorum_set_hash.pack(packer)
     packer.pack_uint(len(self.votes))
     for vote in self.votes:
         vote.pack(packer)
     packer.pack_uint(len(self.accepted))
     for accepted in self.accepted:
         accepted.pack(packer)
예제 #12
0
 def pack(self, packer: Packer) -> None:
     self.threshold.pack(packer)
     packer.pack_uint(len(self.validators))
     for validator in self.validators:
         validator.pack(packer)
     packer.pack_uint(len(self.inner_sets))
     for inner_set in self.inner_sets:
         inner_set.pack(packer)
예제 #13
0
 def pack(self, packer: Packer) -> None:
     self.code.pack(packer)
     if self.code == InflationResultCode.INFLATION_SUCCESS:
         if self.payouts is None:
             raise ValueError("payouts should not be None.")
         packer.pack_uint(len(self.payouts))
         for payout in self.payouts:
             payout.pack(packer)
         return
예제 #14
0
 def pack(self, packer: Packer) -> None:
     self.send_asset.pack(packer)
     self.send_max.pack(packer)
     self.destination.pack(packer)
     self.dest_asset.pack(packer)
     self.dest_amount.pack(packer)
     packer.pack_uint(len(self.path))
     for path in self.path:
         path.pack(packer)
예제 #15
0
파일: messages.py 프로젝트: bartacruz/fgatc
 def send(self):
     ''' packs the Header vars into a buffer '''
     unp = Packer()
     unp.pack_uint(self.magic)
     unp.pack_uint(self.version)
     unp.pack_uint(self.msgid)
     unp.pack_uint(self.msglen)
     unp.pack_uint(0)  # reply_addr y reply_port
     unp.pack_uint(0)  # reply_addr y reply_port
     unp.pack_fstring(8, self.callsign.encode())
     return unp.get_buffer()
예제 #16
0
def gmetric_write(NAME, VAL, TYPE, UNITS, SLOPE, TMAX, DMAX):
    """
    Arguments are in all upper-case to match XML
    """
    packer = Packer()
    packer.pack_int(0)  # type gmetric
    packer.pack_string(TYPE)
    packer.pack_string(NAME)
    packer.pack_string(str(VAL))
    packer.pack_string(UNITS)
    packer.pack_int(slope_str2int[SLOPE])  # map slope string to int
    packer.pack_uint(int(TMAX))
    packer.pack_uint(int(DMAX))
    return packer.get_buffer()
예제 #17
0
파일: tcp.py 프로젝트: saalweachter/fs
def _bytes_from_length(len, closing):
    """
    The RPC standard calls for the length of a message to be sent as the least
    significant 31 bits of an XDR encoded unsigned integer.  The most
    significant bit encodes a True/False bit which indicates that this message
    will be the last.
    """
    assert 0 <= len < 2**31
    from xdrlib import Packer
    if closing:
        len += 2**31
    packer = Packer()
    packer.pack_uint(len)
    return packer.get_buffer()
예제 #18
0
 def __init__(self, stamp, machinename, uid, gid, gids):
     if len(machinename) > 255:
         raise SecError("machinename %s is too long" % machinename)
     if len(gids) > 16:
         raise SecError("gid array too long: %s" % str(gids))
     try:
         p = Packer()
         p.pack_int(stamp)
         p.pack_string(machinename)
         p.pack_uint(uid)
         p.pack_uint(gid)
         p.pack_array(gids, p.pack_uint)
         self.cred = p.get_buffer()
     except Error, e:
         raise SecError("Packing error: %s", str(e))
예제 #19
0
 def __init__(self, stamp, machinename, uid, gid, gids):
     if len(machinename) > 255:
         raise SecError("machinename %s is too long" % machinename)
     if len(gids) > 16:
         raise SecError("gid array too long: %s" % str(gids))
     try:
         p = Packer()
         p.pack_int(stamp)
         p.pack_string(machinename)
         p.pack_uint(uid)
         p.pack_uint(gid)
         p.pack_array(gids, p.pack_uint)
         self.cred = p.get_buffer()
     except Error, e:
         raise SecError("Packing error: %s", str(e))
예제 #20
0
    def sendV2Data(self, sock, address, value):
        packer = Packer()
        packer.pack_enum(0)  # metric_user_defined
        packer.pack_string(self.type)
        packer.pack_string(self.name)
        packer.pack_string(str(value))
        packer.pack_string(self.units)
        if self.slope == 'zero':
            slope = 0
        else:
            slope = 3  # both
        packer.pack_uint(slope)
        packer.pack_uint(self.tmax)
        packer.pack_uint(self.dmax)

        sock.sendto(packer.get_buffer(), address)
예제 #21
0
 def pack(self, packer: Packer) -> None:
     self.code.pack(packer)
     if (self.code == TransactionResultCode.txFEE_BUMP_INNER_SUCCESS
             or self.code == TransactionResultCode.txFEE_BUMP_INNER_FAILED):
         if self.inner_result_pair is None:
             raise ValueError("inner_result_pair should not be None.")
         self.inner_result_pair.pack(packer)
         return
     if (self.code == TransactionResultCode.txSUCCESS
             or self.code == TransactionResultCode.txFAILED):
         if self.results is None:
             raise ValueError("results should not be None.")
         packer.pack_uint(len(self.results))
         for result in self.results:
             result.pack(packer)
         return
     raise ValueError("Invalid code.")
예제 #22
0
def gmetric_write(NAME, VAL, TYPE, UNITS, SLOPE, TMAX, DMAX, GROUP, SPOOF):
    """
    Arguments are in all upper-case to match XML
    """
    packer = Packer()
    HOSTNAME = "test"
    if SPOOF == "":
        SPOOFENABLED = 0
    else:
        SPOOFENABLED = 1
    # Meta data about a metric
    packer.pack_int(128)
    if SPOOFENABLED == 1:
        packer.pack_string(SPOOF)
    else:
        packer.pack_string(HOSTNAME)
    packer.pack_string(NAME)
    packer.pack_int(SPOOFENABLED)
    packer.pack_string(TYPE)
    packer.pack_string(NAME)
    packer.pack_string(UNITS)
    packer.pack_int(slope_str2int[SLOPE])  # map slope string to int
    packer.pack_uint(int(TMAX))
    packer.pack_uint(int(DMAX))
    # Magic number. Indicates number of entries to follow. Put in 1 for GROUP
    if GROUP == "":
        packer.pack_int(0)
    else:
        packer.pack_int(1)
        packer.pack_string("GROUP")
        packer.pack_string(GROUP)

    # Actual data sent in a separate packet
    data = Packer()
    data.pack_int(128 + 5)
    if SPOOFENABLED == 1:
        data.pack_string(SPOOF)
    else:
        data.pack_string(HOSTNAME)
    data.pack_string(NAME)
    data.pack_int(SPOOFENABLED)
    data.pack_string("%s")
    data.pack_string(str(VAL))

    return (packer.get_buffer(), data.get_buffer())
예제 #23
0
파일: gmetric.py 프로젝트: CpuID/statsite
def gmetric_write(NAME, VAL, TYPE, UNITS, SLOPE, TMAX, DMAX, GROUP, SPOOF):
    """
    Arguments are in all upper-case to match XML
    """
    packer = Packer()
    HOSTNAME="test"
    if SPOOF == "":
        SPOOFENABLED=0
    else :
        SPOOFENABLED=1
    # Meta data about a metric
    packer.pack_int(128)
    if SPOOFENABLED == 1:
        packer.pack_string(SPOOF)
    else:
        packer.pack_string(HOSTNAME)
    packer.pack_string(NAME)
    packer.pack_int(SPOOFENABLED)
    packer.pack_string(TYPE)
    packer.pack_string(NAME)
    packer.pack_string(UNITS)
    packer.pack_int(slope_str2int[SLOPE]) # map slope string to int
    packer.pack_uint(int(TMAX))
    packer.pack_uint(int(DMAX))
    # Magic number. Indicates number of entries to follow. Put in 1 for GROUP
    if GROUP == "":
        packer.pack_int(0)
    else:
        packer.pack_int(1)
        packer.pack_string("GROUP")
        packer.pack_string(GROUP)

    # Actual data sent in a separate packet
    data = Packer()
    data.pack_int(128+5)
    if SPOOFENABLED == 1:
        data.pack_string(SPOOF)
    else:
        data.pack_string(HOSTNAME)
    data.pack_string(NAME)
    data.pack_int(SPOOFENABLED)
    data.pack_string("%s")
    data.pack_string(str(VAL))

    return ( packer.get_buffer() ,  data.get_buffer() )
예제 #24
0
파일: security.py 프로젝트: wzugang/pynfs
 def make_reply_verf(self, cred, stat):
     log_gss.debug("CALL:make_reply_verf(%r, %i)" % (cred, stat))
     cred = cred.body
     if stat:
         # Return trivial verf on error
         # NOTE this relies on GSS_S_COMPLETE == rpc.SUCCESS == 0
         return rpclib.NULL_CRED
     elif cred.gss_proc in (RPCSEC_GSS_INIT, RPCSEC_GSS_CONTINUE_INIT):
         # init requires getMIC(seq_window)
         i = WINDOWSIZE
     else:
         # Else return getMIC(cred.seq_num)
         i = cred.seq_num
     p = Packer()
     p.pack_uint(i)
     # XXX BUG - need to set qop
     token = self._get_context(cred.handle).getMIC(p.get_buffer())
     return opaque_auth(RPCSEC_GSS, token)
예제 #25
0
파일: security.py 프로젝트: kofemann/pynfs
 def make_reply_verf(self, cred, stat):
     log_gss.debug("CALL:make_reply_verf(%r, %i)" % (cred, stat))
     cred = cred.body
     if stat:
         # Return trivial verf on error
         # NOTE this relies on GSS_S_COMPLETE == rpc.SUCCESS == 0
         return rpclib.NULL_CRED
     elif cred.gss_proc in (RPCSEC_GSS_INIT, RPCSEC_GSS_CONTINUE_INIT):
         # init requires getMIC(seq_window)
         i = WINDOWSIZE
     else:
         # Else return getMIC(cred.seq_num)
         i = cred.seq_num
     p = Packer()
     p.pack_uint(i)
     # XXX BUG - need to set qop
     token = self._get_context(cred.handle).getMIC(p.get_buffer())
     return opaque_auth(RPCSEC_GSS, token)
예제 #26
0
 def pack(self, packer: Packer) -> None:
     self.ledger_version.pack(packer)
     self.previous_ledger_hash.pack(packer)
     self.scp_value.pack(packer)
     self.tx_set_result_hash.pack(packer)
     self.bucket_list_hash.pack(packer)
     self.ledger_seq.pack(packer)
     self.total_coins.pack(packer)
     self.fee_pool.pack(packer)
     self.inflation_seq.pack(packer)
     self.id_pool.pack(packer)
     self.base_fee.pack(packer)
     self.base_reserve.pack(packer)
     self.max_tx_set_size.pack(packer)
     packer.pack_uint(4)
     for skip_list in self.skip_list:
         skip_list.pack(packer)
     self.ext.pack(packer)
예제 #27
0
 def pack(self, packer: Packer) -> None:
     Integer(self.v).pack(packer)
     if self.v == 0:
         if self.operations is None:
             raise ValueError("operations should not be None.")
         packer.pack_uint(len(self.operations))
         for operation in self.operations:
             operation.pack(packer)
         return
     if self.v == 1:
         if self.v1 is None:
             raise ValueError("v1 should not be None.")
         self.v1.pack(packer)
         return
     if self.v == 2:
         if self.v2 is None:
             raise ValueError("v2 should not be None.")
         self.v2.pack(packer)
         return
예제 #28
0
 def __init__(self, stamp=0, machinename='', uid=0, gid=0, gids=[]):
     if len(machinename) > 255:
         raise SecError("machinename %s is too long" % machinename)
     if len(gids) > 16:
         raise SecError("gid array too long: %s" % str(gids))
     try:
         p = Packer()
         p.pack_int(stamp)
         try:    # for python2
             p.pack_string(machinename)
         except: # for python3
             p.pack_string(bytes(machinename, 'utf-8'))
         p.pack_uint(uid)
         p.pack_uint(gid)
         p.pack_array(gids, p.pack_uint)
         self.cred = p.get_buffer()
     except Error as e:
         raise SecError("Packing error: %s", str(e))
     self.uid = uid
     self.gid = gid
예제 #29
0
def gmetric_meta(NAME, TYPE, UNITS, SLOPE, TMAX, DMAX, EXTRAS=None):
    """
    Arguments are in all upper-case to match XML
    """
    packer = Packer()
    packer.pack_int(128)  # "gmetadata_full"
    packer.pack_string('nickg-macbook.local')
    packer.pack_string(NAME)
    packer.pack_bool(False)

    packer.pack_string(TYPE)
    packer.pack_string(NAME)
    packer.pack_string(UNITS)
    packer.pack_int(slope_str2int[SLOPE]) # map slope string to int
    packer.pack_uint(int(TMAX))
    packer.pack_uint(int(DMAX))
    if EXTRAS is None:
        packer.pack_uint(0)
    else:
        packer.pack_uint(len(EXTRAS))
        for k,v in EXTRAS.iteritems():
            packer.pack_string(k)
            packer.pack_string(v)

    return packer.get_buffer()
예제 #30
0
def gmetric_write(NAME, VAL, TYPE, UNITS, SLOPE, TMAX, DMAX, GROUP, SPOOF):
    """
    Arguments are in all upper-case to match XML
    """
    packer = Packer()
    HOSTNAME = 'test'
    if SPOOF == '':
        SPOOFENABLED = 0
    else:
        SPOOFENABLED = 1
    packer.pack_int(128)
    if SPOOFENABLED == 1:
        packer.pack_string(SPOOF)
    else:
        packer.pack_string(HOSTNAME)
    packer.pack_string(NAME)
    packer.pack_int(SPOOFENABLED)
    packer.pack_string(TYPE)
    packer.pack_string(NAME)
    packer.pack_string(UNITS)
    packer.pack_int(slope_str2int[SLOPE])
    packer.pack_uint(int(TMAX))
    packer.pack_uint(int(DMAX))
    if GROUP == '':
        packer.pack_int(0)
    else:
        packer.pack_int(1)
        packer.pack_string('GROUP')
        packer.pack_string(GROUP)
    data = Packer()
    data.pack_int(133)
    if SPOOFENABLED == 1:
        data.pack_string(SPOOF)
    else:
        data.pack_string(HOSTNAME)
    data.pack_string(NAME)
    data.pack_int(SPOOFENABLED)
    data.pack_string('%s')
    data.pack_string(str(VAL))
    return (packer.get_buffer(), data.get_buffer())
예제 #31
0
def gmetric_meta(NAME, TYPE, UNITS, SLOPE, TMAX, DMAX, EXTRAS=None):
    """
    Arguments are in all upper-case to match XML
    """
    packer = Packer()
    packer.pack_int(128)  # "gmetadata_full"
    packer.pack_string('nickg-macbook.local')
    packer.pack_string(NAME)
    packer.pack_bool(False)

    packer.pack_string(TYPE)
    packer.pack_string(NAME)
    packer.pack_string(UNITS)
    packer.pack_int(slope_str2int[SLOPE])  # map slope string to int
    packer.pack_uint(int(TMAX))
    packer.pack_uint(int(DMAX))
    if EXTRAS is None:
        packer.pack_uint(0)
    else:
        packer.pack_uint(len(EXTRAS))
        for k, v in EXTRAS.iteritems():
            packer.pack_string(k)
            packer.pack_string(v)

    return packer.get_buffer()
 def pack(self, packer: Packer) -> None:
     self.quorum_set_hash.pack(packer)
     self.ballot.pack(packer)
     if self.prepared is None:
         packer.pack_uint(0)
     else:
         packer.pack_uint(1)
         self.prepared.pack(packer)
     if self.prepared_prime is None:
         packer.pack_uint(0)
     else:
         packer.pack_uint(1)
         self.prepared_prime.pack(packer)
     self.n_c.pack(packer)
     self.n_h.pack(packer)
예제 #33
0
 def pack(self, packer: Packer) -> None:
     self.code.pack(packer)
     if (self.code == TransactionResultCode.txSUCCESS
             or self.code == TransactionResultCode.txFAILED):
         if self.results is None:
             raise ValueError("results should not be None.")
         packer.pack_uint(len(self.results))
         for result in self.results:
             result.pack(packer)
         return
     if (self.code == TransactionResultCode.txTOO_EARLY
             or self.code == TransactionResultCode.txTOO_LATE
             or self.code == TransactionResultCode.txMISSING_OPERATION
             or self.code == TransactionResultCode.txBAD_SEQ
             or self.code == TransactionResultCode.txBAD_AUTH
             or self.code == TransactionResultCode.txINSUFFICIENT_BALANCE
             or self.code == TransactionResultCode.txNO_ACCOUNT
             or self.code == TransactionResultCode.txINSUFFICIENT_FEE
             or self.code == TransactionResultCode.txBAD_AUTH_EXTRA
             or self.code == TransactionResultCode.txINTERNAL_ERROR
             or self.code == TransactionResultCode.txNOT_SUPPORTED
             or self.code == TransactionResultCode.txBAD_SPONSORSHIP):
         return
예제 #34
0
파일: gmetric.py 프로젝트: Pluckyduck/eve
def gmetric_write(NAME, VAL, TYPE, UNITS, SLOPE, TMAX, DMAX, GROUP, SPOOF):
    packer = Packer()
    HOSTNAME = 'test'
    if SPOOF == '':
        SPOOFENABLED = 0
    else:
        SPOOFENABLED = 1
    packer.pack_int(128)
    if SPOOFENABLED == 1:
        packer.pack_string(SPOOF)
    else:
        packer.pack_string(HOSTNAME)
    packer.pack_string(NAME)
    packer.pack_int(SPOOFENABLED)
    packer.pack_string(TYPE)
    packer.pack_string(NAME)
    packer.pack_string(UNITS)
    packer.pack_int(slope_str2int[SLOPE])
    packer.pack_uint(int(TMAX))
    packer.pack_uint(int(DMAX))
    if GROUP == '':
        packer.pack_int(0)
    else:
        packer.pack_int(1)
        packer.pack_string('GROUP')
        packer.pack_string(GROUP)
    data = Packer()
    data.pack_int(133)
    if SPOOFENABLED == 1:
        data.pack_string(SPOOF)
    else:
        data.pack_string(HOSTNAME)
    data.pack_string(NAME)
    data.pack_int(SPOOFENABLED)
    data.pack_string('%s')
    data.pack_string(str(VAL))
    return (packer.get_buffer(), data.get_buffer())
예제 #35
0
파일: messages.py 프로젝트: bartacruz/fgatc
 def send(self):
     try:
         unp = Packer() 
         unp.pack_fstring(96, self.model.encode())
         unp.pack_double(self.time)
         unp.pack_double(self.lag)
         unp.pack_farray(3, self.position, unp.pack_double)
         unp.pack_farray(3, self.orientation, unp.pack_float)
         unp.pack_farray(3, self.linear_vel, unp.pack_float)
         unp.pack_farray(3, self.angular_vel, unp.pack_float)
         unp.pack_farray(3, self.linear_accel, unp.pack_float)
         unp.pack_farray(3, self.angular_accel, unp.pack_float)
         unp.pack_uint(0)
         self.properties.send(unp)
         msgbuf = unp.get_buffer()
         headbuf = self.header.send()
         self.header.msglen = len(headbuf + msgbuf)
         #print("setting len=",self.header.msglen, len(headbuf + msgbuf))
         headbuf = self.header.send()
         #print("len2=",self.header.msglen, len(headbuf+msgbuf))
         return headbuf + msgbuf
     except:
         llogger.exception("ERROR creating msg")
         print(self.model)
예제 #36
0
 def pack(self, packer: Packer) -> None:
     self.ledger_header.pack(packer)
     self.tx_set.pack(packer)
     packer.pack_uint(len(self.tx_processing))
     for tx_processing in self.tx_processing:
         tx_processing.pack(packer)
     packer.pack_uint(len(self.upgrades_processing))
     for upgrades_processing in self.upgrades_processing:
         upgrades_processing.pack(packer)
     packer.pack_uint(len(self.scp_info))
     for scp_info in self.scp_info:
         scp_info.pack(packer)
예제 #37
0
 def pack(self, packer: Packer) -> None:
     self.source_account_ed25519.pack(packer)
     self.fee.pack(packer)
     self.seq_num.pack(packer)
     if self.time_bounds is None:
         packer.pack_uint(0)
     else:
         packer.pack_uint(1)
         self.time_bounds.pack(packer)
     self.memo.pack(packer)
     packer.pack_uint(len(self.operations))
     for operation in self.operations:
         operation.pack(packer)
     self.ext.pack(packer)
예제 #38
0
 def pack(self, packer: Packer) -> None:
     self.type.pack(packer)
     if self.type == ClaimPredicateType.CLAIM_PREDICATE_UNCONDITIONAL:
         return
     if self.type == ClaimPredicateType.CLAIM_PREDICATE_AND:
         if self.and_predicates is None:
             raise ValueError("and_predicates should not be None.")
         packer.pack_uint(len(self.and_predicates))
         for and_predicate in self.and_predicates:
             and_predicate.pack(packer)
         return
     if self.type == ClaimPredicateType.CLAIM_PREDICATE_OR:
         if self.or_predicates is None:
             raise ValueError("or_predicates should not be None.")
         packer.pack_uint(len(self.or_predicates))
         for or_predicate in self.or_predicates:
             or_predicate.pack(packer)
         return
     if self.type == ClaimPredicateType.CLAIM_PREDICATE_NOT:
         if self.not_predicate is None:
             packer.pack_uint(0)
             return
         packer.pack_uint(1)
         if self.not_predicate is None:
             raise ValueError("not_predicate should not be None.")
         self.not_predicate.pack(packer)
         return
     if self.type == ClaimPredicateType.CLAIM_PREDICATE_BEFORE_ABSOLUTE_TIME:
         if self.abs_before is None:
             raise ValueError("abs_before should not be None.")
         self.abs_before.pack(packer)
         return
     if self.type == ClaimPredicateType.CLAIM_PREDICATE_BEFORE_RELATIVE_TIME:
         if self.rel_before is None:
             raise ValueError("rel_before should not be None.")
         self.rel_before.pack(packer)
         return
     raise ValueError("Invalid type.")
예제 #39
0
 def pack(self, packer: Packer) -> None:
     self.account_id.pack(packer)
     self.balance.pack(packer)
     self.seq_num.pack(packer)
     self.num_sub_entries.pack(packer)
     if self.inflation_dest is None:
         packer.pack_uint(0)
     else:
         packer.pack_uint(1)
         self.inflation_dest.pack(packer)
     self.flags.pack(packer)
     self.home_domain.pack(packer)
     self.thresholds.pack(packer)
     packer.pack_uint(len(self.signers))
     for signer in self.signers:
         signer.pack(packer)
     self.ext.pack(packer)
예제 #40
0
    def sendMetadata(self, sock, address):
        self.lastMetadataSendTime = time.time()
        packer = Packer()
        packer.pack_enum(self.formatIDs['full'])
        packer.pack_string(self.hostname)
        packer.pack_string(self.name)
        packer.pack_bool(False)  # spoof = false
        packer.pack_string(self.type)
        packer.pack_string(self.name)
        packer.pack_string(self.units)
        if self.slope == 'zero':
            slope = 0
        else:
            slope = 3
        packer.pack_uint(slope)
        packer.pack_uint(self.tmax)
        packer.pack_uint(self.dmax)

        packer.pack_uint(len(self.meta))  # array length
        for name, value in self.meta.items():
            packer.pack_string(name)
            packer.pack_string(value)

        sock.sendto(packer.get_buffer(), address)
예제 #41
0
 def compute_tlv(tag, message):
     packer = Packer()
     packer.pack_uint(tag)
     packer.pack_string(message)
     return packer.get_buffer()
예제 #42
0
 def pack(self, packer: Packer) -> None:
     self.tx.pack(packer)
     packer.pack_uint(len(self.signatures))
     for signature in self.signatures:
         signature.pack(packer)
예제 #43
0
파일: rpc.py 프로젝트: saalweachter/fs
    def handle_message(self, opaque_bytes, client_id):
        """
        Handles a message, start to finish.
        Takes the opaque bytes representing the XDR encoded RPC message.
        Produces an RPC reply, also encoded as opaque bytes.
        """
        from xdrlib import Unpacker, Packer
        unpacker = Unpacker(opaque_bytes)
        msg = rpc_msg.unpack(unpacker)
        print(msg.body.mtype.value)
        if msg.body.mtype != msg_type.CALL:
            print("No reply!")
            return None # do not reply to such a bad message.
        #response = self.handle_message(msg,
        #                               opaque_bytes[unpacker.get_position():])
        print("Well-formed message!")
        print("rpc version: %d" % msg.body.cbody.rpcvers)
        print("program id: %d" % msg.body.cbody.prog)
        print("version id: %d" % msg.body.cbody.vers)
        print("procedure id: %d" % msg.body.cbody.proc)
        print("cred flavor: %d" % msg.body.cbody.cred.flavor)
        print("verf flavor: %d" % msg.body.cbody.verf.flavor)
        print("remaining bytes: %s" % opaque_bytes[unpacker.get_position():])

        if msg.body.cbody.cred.flavor == auth_flavor.AUTH_SYS:
            print("using system auth")
            unpacker2 = Unpacker(msg.body.cbody.cred.body.bytes)
            params = authsys_parms.unpack(unpacker2)
            print(params)
            id = self.next_short_id
            self.next_short_id += 1
            self.system_auth[id] = params
            packer = Packer()
            packer.pack_uint(id)
            verf = opaque_auth(flavor=auth_flavor.AUTH_SHORT,
                               body=packer.get_buffer())
        else:
            verf = opaque_auth.NONE()

        def _pack(reply):
            packer = Packer()
            reply.pack(packer)
            return packer.get_buffer()
        _body = rpc_msg.body
        _rbody = reply_body
        _rreply = rejected_reply
        _areply = accepted_reply
        _rdata = accepted_reply.reply_data
        
        if msg.body.cbody.rpcvers != 2:
            reply = rpc_msg(xid=msg.xid,
                            body=_body(mtype=msg_type.REPLY,
                                       rbody=_rbody(stat=reply_stat.MSG_DENIED,
                                                    rreply=_rreply(stat=reject_stat.RPC_MISMATCH,
                                                                   mismatch_info=mismatch_info(low=2, high=2)))))
            return _pack(reply)

        if msg.body.cbody.prog not in self.programs:
            print("no such program!")
            reply = rpc_msg(xid=msg.xid,
                            body=_body(mtype=msg_type.REPLY,
                                       rbody=_rbody(stat=reply_stat.MSG_ACCEPTED,
                                                    areply=_areply(verf=verf,
                                                                   reply_data=_rdata(stat=accept_stat.PROG_UNAVAIL)))))
            return _pack(reply)

        program = self.programs[msg.body.cbody.prog]
        print("program: %s" % str(program))
        version = program.get_version_impl(msg.body.cbody.vers)
        print("version: %s" % str(version))
        procedure = version.get_procedure_by_id(msg.body.cbody.proc)
        print("procedure: %s" % str(procedure))
        print("procedure.arg_type: %s" % str(procedure.argument_type))
        args = procedure.argument_type.unpack(unpacker)
        print("args: %s" % str(args))
        response = procedure(version, msg, args)
        print("response: %s" % str(response))
        reply = rpc_msg(xid=msg.xid,
                        body=_body(mtype=msg_type.REPLY,
                                   rbody=_rbody(stat=reply_stat.MSG_ACCEPTED,
                                                areply=_areply(verf=verf,
                                                               reply_data=_rdata(stat=accept_stat.SUCCESS)))))
        print("reply: %s" % str(reply))
        packer = Packer()
        reply.pack(packer)
        response.pack(packer)
        print("bytes: %s" % str(packer.get_buffer()))
        return packer.get_buffer()
예제 #44
0
    def _gmetric(self, name, val, metric_type, units, slope, tmax, dmax, group, title, description, spoof):

        meta = Packer()
        HOSTNAME = socket.gethostname()
        if spoof:
            SPOOF_ENABLED = 1
        else:
            SPOOF_ENABLED = 0

        # Meta data about a metric
        packet_type = 128
        meta.pack_int(packet_type)
        if SPOOF_ENABLED == 1:
            meta.pack_string(spoof)
        else:
            meta.pack_string(HOSTNAME)
        meta.pack_string(name)
        meta.pack_int(SPOOF_ENABLED)
        meta.pack_string(metric_type)
        meta.pack_string(name)
        meta.pack_string(units)
        meta.pack_int(METRIC_SLOPES[slope])  # map slope string to int
        meta.pack_uint(int(tmax))
        meta.pack_uint(int(dmax))

        extra_data = 0
        if group:
            extra_data += 1
        if title:
            extra_data += 1
        if description:
            extra_data += 1

        meta.pack_int(extra_data)
        if group:
            for g in group.split(','):
                meta.pack_string("GROUP")
                meta.pack_string(g)
        if title:
            meta.pack_string("TITLE")
            meta.pack_string(title)
        if description:
            meta.pack_string("DESC")
            meta.pack_string(description)

        # Actual data sent in a separate packet
        data = Packer()
        packet_type = METRIC_TYPES[metric_type]
        data.pack_int(packet_type)
        if SPOOF_ENABLED == 1:
            data.pack_string(spoof)
        else:
            data.pack_string(HOSTNAME)
        data.pack_string(name)
        data.pack_int(SPOOF_ENABLED)

        if metric_type in ['int8', 'uint8', 'int16', 'uint16', 'int32']:
            data.pack_string("%d")
            data.pack_int(int(val))
        if metric_type == 'uint32':
            data.pack_string("%u")
            data.pack_uint(long(val))
        if metric_type == 'string':
            data.pack_string("%s")
            data.pack_string(str(val))
        if metric_type == 'float':
            data.pack_string("%f")
            data.pack_float(float(val))
        if metric_type == 'double':
            data.pack_string("%f")
            data.pack_double(float(val))  # XXX - double or float?

        return meta.get_buffer(), data.get_buffer()
예제 #45
0
def _rpcPacket():			#Build RPC portmap call
        
    data = Packer()
    data.pack_uint(int(random() * 0xffffffff))       # Transaction Identifier (xid)
    data.pack_enum(CALL)                                    # Message Type
    data.pack_uint(2)                                       # RPC version
    data.pack_enum(PORTMAP)                                 # Program 
    data.pack_uint(2)                                       # Program Version
    data.pack_enum(GETPORT)                                 # Process
    data.pack_enum(AUTH_NULL)                               # Credentials
    data.pack_uint(0)                                       # Credentials length
    data.pack_enum(AUTH_NULL)                               # Verifier 
    data.pack_uint(0)                                       # Verifier Length
    data.pack_enum(VXI11_CORE)                              # Called Program
    data.pack_uint(1)                                       # Program Version
    data.pack_enum(TCP)                                     # Program Protocol
    data.pack_uint(0)                                       # Port
    
    return data.get_buffer()
예제 #46
0
    def _gmetric(self, name, val, type, units, slope, tmax, dmax, group, title, description, spoof):
        """
        Arguments are in all upper-case to match XML
        """

        meta = Packer()
        HOSTNAME=socket.gethostname()
        if spoof == "":
            SPOOFENABLED=0
        else :
            SPOOFENABLED=1

        # Meta data about a metric
        packet_type = 128
        meta.pack_int(packet_type)
        if SPOOFENABLED == 1:
            meta.pack_string(spoof)
        else:
            meta.pack_string(HOSTNAME)
        meta.pack_string(name)
        meta.pack_int(SPOOFENABLED)
        meta.pack_string(type)
        meta.pack_string(name)
        meta.pack_string(units)
        meta.pack_int(SLOPES[slope]) # map slope string to int
        meta.pack_uint(int(tmax))
        meta.pack_uint(int(dmax))

        extra_data = 0
        if group != "":
            extra_data += 1
        if title != "":
            extra_data += 1
        if description != "":
            extra_data += 1

        meta.pack_int(extra_data)
        if group != "":
            meta.pack_string("GROUP")
            meta.pack_string(group)
        if title != "":
            meta.pack_string("TITLE")
            meta.pack_string(title)
        if description != "":
            meta.pack_string("DESC")
            meta.pack_string(description)

        # Actual data sent in a separate packet
        data = Packer()
        packet_type = TYPES[type]
        data.pack_int(packet_type)
        if SPOOFENABLED == 1:
            data.pack_string(spoof)
        else:
            data.pack_string(HOSTNAME)
        data.pack_string(name)
        data.pack_int(SPOOFENABLED)

        if type in ['int8','uint8','int16','uint16','int32']:
            data.pack_string("%d")
            data.pack_int(int(val))
        if type == 'uint32':
            data.pack_string("%u")
            data.pack_uint(long(val))
        if type == 'string':
            data.pack_string("%s")
            data.pack_string(str(val))
        if type == 'float':
            data.pack_string("%f")
            data.pack_float(float(val))
        if type == 'double':
            data.pack_string("%f")
            data.pack_double(float(val))  # XXX - double or float?

        return (meta.get_buffer(), data.get_buffer())