def process_header(receiver_header, RSA_PUBLIC_KEY):
    # receiver_header = json_bytes_loads(receiver_header)
    #header class
    receiver_header = Header(receiver_header['SYN'], RECEIVER_ACK)
    receiver_header.change_SYN_with_ACK()
    receiver_header.increment_ACK()
    receiver_header.add_rsa_public_key(RSA_PUBLIC_KEY)
    receiver_header = receiver_header.get_header_data()

    receiver_header = json_bytes_dumps(receiver_header)
    return receiver_header
Exemplo n.º 2
0
def process_header(sender_header):
    sender_header = Header(sender_header['SYN'], sender_header['ACK'])
    sender_header.change_SYN_with_ACK()
    sender_header.increment_ACK()
    sender_header = sender_header.get_header_data()

    sender_header = json_bytes_dumps(sender_header)
    return sender_header
def terminate_receiver_connection(sock):
    while True:
        #send a json with type fin
        t_sender_header = Header(T_SENDER_SYN, None)
        t_sender_header = t_sender_header.get_header_data()
        t_sender_header['type'] = 'fin'

        t_sender_header = json_bytes_dumps(t_sender_header)
        sock.sendto(t_sender_header, RECEIVER_ADDRESS)
        #receive and updated ACK
        t_recv = sock.recvfrom(BUFFER_SIZE)[0]
        t_recv = json_bytes_loads(t_recv)

        if t_recv['ACK'] == T_SENDER_SYN + 1:
            t_sender_header = Header(t_recv['SYN'], t_recv['ACK'])
            t_sender_header.change_SYN_with_ACK()
            t_sender_header.increment_ACK()
            t_sender_header = t_sender_header.get_header_data()
            t_sender_header = json_bytes_dumps(t_sender_header)
            sock.sendto(t_sender_header, RECEIVER_ADDRESS)
            print(x * 10 + "Connection terminated")
            break
        else:
            print(x * 10 + "Error during canceling connection.")
def terminate_receiver_connection(sock, t_recv, SENDER_ADDRESS):
    while True:
        #receives SYN from sender and send updated ACK to sender for it to stop
        t_send_header = Header(t_recv['SYN'], T_RECEIVER_SYN)
        t_send_header.change_SYN_with_ACK()
        t_send_header.increment_ACK()
        t_send_header = t_send_header.get_header_data()
        t_send_header = json_bytes_dumps(t_send_header)
        sock.sendto(t_send_header, SENDER_ADDRESS)

        t_recv = sock.recvfrom(BUFFER_SIZE)[0]
        t_recv = json_bytes_loads(t_recv)

        if t_recv['ACK'] == T_RECEIVER_SYN + 1:
            print(x * 10 + "Connection terminated")
            return True
        else:
            print(x * 10 + "Error during stopping connection.")
            return False
Exemplo n.º 5
0
def initial_SYN():
    sender_header = Header(SENDER_SYN, None).get_header_data()
    sender_header = json_bytes_dumps(sender_header)
    return sender_header