Пример #1
0
    def setupClientFunctions(self):
        self.client_cf = ffi.new('struct curvecpr_client_messager_glib_cf *')

        @ffi.callback(
            'int(struct curvecpr_client_messager_glib *, const unsigned char *, size_t)'
        )
        def send(client, buf, num):
            print 'writing', num, 'bytes'
            try:
                self.transport.write(
                    ffi.buffer(buf, num)[:], (self.host, self.port))
            except Exception:
                log.err(None, 'error sending curvecp datagram')
                return -1
            else:
                return 0

        self._funcs.append(send)

        @ffi.callback(
            'int(struct curvecpr_client_messager_glib *, const unsigned char *, size_t)'
        )
        def recv(client, buf, num):
            print 'got', num, 'bytes', ` ffi.buffer(buf, num)[:] `
            return 0

        self._funcs.append(recv)

        @ffi.callback(
            'void(struct curvecpr_client_messager_glib *, enum curvecpr_block_eofflag)'
        )
        def finished(client, flag):
            print 'finished', flag
            C.curvecpr_client_messager_glib_finish(self.client)

        self._funcs.append(finished)

        self.client_cf = ffi.new(
            'struct curvecpr_client_messager_glib_cf *', {
                'ops': {
                    'send': send,
                    'recv': recv,
                    'finished': finished,
                    'next_nonce': nextNonce,
                },
            })
Пример #2
0
    def setupClientFunctions(self):
        self.client_cf = ffi.new('struct curvecpr_client_messager_glib_cf *')

        @ffi.callback('int(struct curvecpr_client_messager_glib *, const unsigned char *, size_t)')
        def send(client, buf, num):
            print 'writing', num, 'bytes'
            try:
                self.transport.write(ffi.buffer(buf, num)[:], (self.host, self.port))
            except Exception:
                log.err(None, 'error sending curvecp datagram')
                return -1
            else:
                return 0

        self._funcs.append(send)

        @ffi.callback('int(struct curvecpr_client_messager_glib *, const unsigned char *, size_t)')
        def recv(client, buf, num):
            print 'got', num, 'bytes', `ffi.buffer(buf, num)[:]`
            return 0

        self._funcs.append(recv)

        @ffi.callback('void(struct curvecpr_client_messager_glib *, enum curvecpr_block_eofflag)')
        def finished(client, flag):
            print 'finished', flag
            C.curvecpr_client_messager_glib_finish(self.client)

        self._funcs.append(finished)

        self.client_cf = ffi.new('struct curvecpr_client_messager_glib_cf *', {
            'ops': {
                'send': send,
                'recv': recv,
                'finished': finished,
                'next_nonce': nextNonce,
            },
        })
Пример #3
0
    def setupClient(self):
        self.client = ffi.new('struct curvecpr_client_messager_glib *')
        self.setupClientFunctions()

        self.client_cf.pending_maximum = 2 ** 32
        self.client_cf.sendmarkq_maximum = 2 ** 16
        self.client_cf.recvmarkq_maximum = 2 ** 16

        self.client_cf[0].my_extension = self.clientExtension
        self.client_cf[0].my_global_pk = str(self.clientKey.public_key)
        self.client_cf[0].my_global_sk = str(self.clientKey)

        self.client_cf[0].their_extension = self.serverExtension
        self.client_cf[0].their_global_pk = str(self.serverKey)
        C.curvecpr_util_encode_domain_name(self.client_cf[0].their_domain_name, 'example.com')

        C.curvecpr_client_messager_glib_new(self.client, self.client_cf)
Пример #4
0
    def setupClient(self):
        self.client = ffi.new('struct curvecpr_client_messager_glib *')
        self.setupClientFunctions()

        self.client_cf.pending_maximum = 2**32
        self.client_cf.sendmarkq_maximum = 2**16
        self.client_cf.recvmarkq_maximum = 2**16

        self.client_cf[0].my_extension = self.clientExtension
        self.client_cf[0].my_global_pk = str(self.clientKey.public_key)
        self.client_cf[0].my_global_sk = str(self.clientKey)

        self.client_cf[0].their_extension = self.serverExtension
        self.client_cf[0].their_global_pk = str(self.serverKey)
        C.curvecpr_util_encode_domain_name(self.client_cf[0].their_domain_name,
                                           'example.com')

        C.curvecpr_client_messager_glib_new(self.client, self.client_cf)