Commit 5cc72c25 authored by Andreas Schmidt's avatar Andreas Schmidt
Browse files

Evalution works technically.

parent f575c60a
Loading
Loading
Loading
Loading
Loading
+12 −7
Original line number Diff line number Diff line
import sys
sys.path.insert(0, "./build")
import prrt
import time as time
import threading

class receiverThread(threading.Thread):
@@ -12,8 +13,11 @@ class receiverThread(threading.Thread):
        print("Receiving")
        while(1):
            print("Recv")
            p = self.sock.recv()
            print(p)
            len, data = self.sock.recv()
            v = data[:len].decode('UTF-8')
            print(len, v)
            time.sleep(1)


        print("Receiver Thread")

@@ -24,16 +28,17 @@ class senderThread(threading.Thread):

    def run(self):
        print("Connecting")
        self.sock.connect("localhost", 5000)
        self.sock.connect("127.0.0.1", 5000)
        print("Connected")
        for i in range(10):
            self.sock.send("Test")
        print("Sent")
            time.sleep(0.001)

        self.sock.close();

if __name__ == "__main__":
    recvThread = receiverThread()
    recvThread.daemon = True
    sendThread = senderThread()
    sendThread.daemon = True

    recvThread.start()
    sendThread.start()
+2 −1
Original line number Diff line number Diff line
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize

setup(
    include_dirs=["./src"],
    ext_modules = cythonize("src/cython/prrt.pyx")
    ext_modules = cythonize(["src/cython/prrt.pyx"], gdb_debug=True)
)
 No newline at end of file
+14 −13
Original line number Diff line number Diff line
from libc.stdint cimport uint32_t, uint16_t, uint8_t, int32_t
from libc.string cimport const_char

cdef extern from "pthread.h" nogil:
    ctypedef struct pthread_t:
@@ -10,19 +11,19 @@ cdef extern from "pthread.h" nogil:
    ctypedef struct pthread_cond_t:
        pass

cdef extern from "prrt/stores/forward_packet_table.h" nogil:
cdef extern from "prrt/stores/forward_packet_table.h":
    cdef struct prrtForwardPacketTable:
        pass

    ctypedef prrtForwardPacketTable PrrtForwardPacketTable

cdef extern from "prrt/vdmcode/block_code.h" nogil:
cdef extern from "prrt/vdmcode/block_code.h":
    cdef struct prrtCoder:
        pass

    ctypedef prrtCoder PrrtCoder

cdef extern from "prrt/coding_params.h" nogil:
cdef extern from "prrt/coding_params.h":
    cdef struct prrtCodingParams:
        uint8_t k;
        uint8_t r;
@@ -31,7 +32,7 @@ cdef extern from "prrt/coding_params.h" nogil:

    ctypedef prrtCodingParams PrrtCodingParams

cdef extern from "util/list.h" nogil:
cdef extern from "util/list.h":
    cdef struct list:
        pass

@@ -50,7 +51,7 @@ cdef extern from "util/list.h" nogil:

    void *List_remove(List *list, const ListNode *node)

cdef extern from "prrt/block.h" nogil:
cdef extern from "prrt/block.h":
    cdef struct prrtBlock:
        uint32_t data_count
        uint32_t redundancy_count
@@ -63,7 +64,7 @@ cdef extern from "prrt/block.h" nogil:

    ctypedef prrtBlock PrrtBlock

cdef extern from "prrt/packet.h" nogil:
cdef extern from "prrt/packet.h":
    cdef struct prrtPacket:
        uint8_t type_priority;
        uint8_t index;
@@ -73,7 +74,7 @@ cdef extern from "prrt/packet.h" nogil:

    ctypedef prrtPacket PrrtPacket

cdef extern from "prrt/socket.h" nogil:
cdef extern from "prrt/socket.h":
    ctypedef struct PrrtReceiver:
        const char* host_name
        uint16_t port
@@ -109,14 +110,14 @@ cdef extern from "prrt/socket.h" nogil:

    ctypedef prrtSocket PrrtSocket

    cdef PrrtSocket* PrrtSocket_create(uint16_t port, uint8_t is_sender) nogil
    int PrrtSocket_close(const PrrtSocket *sock_ptr) nogil
    int PrrtSocket_connect(PrrtSocket *sock_ptr, const char *host, const uint16_t port) nogil
    int PrrtSocket_send(PrrtSocket *sock_ptr, const void *data, const size_t data_len) nogil
    cdef PrrtSocket* PrrtSocket_create(uint16_t port, uint8_t is_sender)
    int PrrtSocket_close(const PrrtSocket *sock_ptr)
    int PrrtSocket_connect(PrrtSocket *sock_ptr, const_char *host, const uint16_t port)
    int PrrtSocket_send(PrrtSocket *sock_ptr, const uint8_t *data, const size_t data_len)
    int32_t PrrtSocket_recv(PrrtSocket *sock_ptr, void *buf_ptr) nogil
    PrrtPacket *PrrtSocket_recv_feedback(const PrrtSocket *sock_ptr, void *bufin, const size_t length) nogil
    PrrtPacket *PrrtSocket_recv_feedback(const PrrtSocket *sock_ptr, void *bufin, const size_t length)

cdef extern from "util/bptree.h" nogil:
cdef extern from "util/bptree.h":
    ctypedef struct BPTreeNode:
        pass

+15 −9
Original line number Diff line number Diff line
from libc.stdint cimport uint32_t, uint16_t, uint8_t
from libc.stdint cimport uint32_t, uint16_t, uint8_t, int32_t
cimport cprrt

cdef extern from "prrt/stores/forward_packet_table.c":
@@ -60,13 +60,19 @@ cdef class PrrtSocket:
        self.isSender = isSender

    def recv(self):
        cdef char buf[65536]
        cdef bytes s
        len = cprrt.PrrtSocket_recv(self._c_socket, <void*> buf)
        s = buf
        s[len] = '\0'
        return s
        cdef char buffer[65536]
        cdef int32_t len
        with nogil:
            len = cprrt.PrrtSocket_recv(self._c_socket, <void*> buffer)
        return len, buffer

    def connect(self, host, port):
        print "Connecting to", host, "on port", str(port)
        cprrt.PrrtSocket_connect(self._c_socket, host, port)
        cdef bytes encodedHost = host.encode("utf-8")
        cprrt.PrrtSocket_connect(self._c_socket, encodedHost, port)

    def send(self, data):
        cdef bytes encodedData = data.encode("utf-8")
        cprrt.PrrtSocket_send(self._c_socket, encodedData, len(data))

    def close(self):
        cprrt.PrrtSocket_close(self._c_socket)
 No newline at end of file
+2 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ bool send_packet(PrrtSocket *sock_ptr, PrrtPacket *packet) {
    // SENDING TO ALL RECEIVERS
    LIST_FOREACH(sock_ptr->receivers, first, next, cur) {
        PrrtReceiver* recv = cur->value;

        struct hostent *hp;

        struct sockaddr_in targetaddr;
@@ -28,6 +29,7 @@ bool send_packet(PrrtSocket *sock_ptr, PrrtPacket *packet) {
        targetaddr.sin_port = htons(recv->port);

        hp = gethostbyname(recv->host_name);
        check(hp != NULL, "Could not resolve host '%s'.", recv->host_name)
        memcpy((void *) &targetaddr.sin_addr, hp->h_addr_list[0], (size_t) hp->h_length);

        ssize_t sendtoRes = sendto(sock_ptr->dataSocketFd, buf, length, 0, (struct sockaddr *) &targetaddr, sizeof(targetaddr));
Loading