Ejemplo n.º 1
0
def listen():
    try:
        serversocket = network.start_server('localhost', RELAY_PORT)
        next_ip = None
        while True:
            logger.log('CURRENT RELAY NODE: ' + str(RELAY_PORT))
            logger.log('RECIEVING PORT:' + str(RELAY_PORT) +
                       ' FORWARDING PORT:' + str(FORWARDING_PORT))

            clientsocket, address = serversocket.accept()
            payload = network.recv_by_size(clientsocket)
            previous_ip = parse_address(address)
            logger.log('received payload from: ', previous_ip)
            logger.log('Payload (trunc): ', payload[:100], newline=True)
            logger.header('---- BEGIN DECRYPTION OF RECEIVED PAYLOAD ----')
            next_ip, message = deserialize_payload(payload)

            logger.log('begin forwarding payload to next node...')
            response = forward_payload(next_ip, message)
            if response is not None:
                '''
            Case: send to previous_ip
            '''
                # encrypt layer
                logger.log('Response returned from: ' + next_ip, newline=True)
                logger.header('---- BEGIN ENCRYPTION OF RETURN PAYLOAD ----')
                logger.log('Payload being encrypted (trunc):', response[:100])

                logger.log('aes_key used:', DECRYPTED_AES_KEY)
                encrypted_payload = network.prepend_length(
                    serialize_payload(response))

                logger.log('send payload to previous node: ', previous_ip)
                clientsocket.sendall(encrypted_payload)

            clientsocket.close()
    except Exception:
        logger.error("Unable to connect to server")
        logger.error(traceback.format_exc())
    return
Ejemplo n.º 2
0
# This file is an entry point of server.
# Copyright Ivan Remen ([email protected]) BMSTU 2013

from network import start_server

if __name__ == '__main__':
    start_server()
Ejemplo n.º 3
0
import network
import database
import sys
from datetime import datetime
import json
import log
import traceback

args = sys.argv[1:]

network.start_server()

while True:
	command = input()

	if command == "net off":
		if not network.ENABLED:
			log.info("net", "Networking is already disabled. enable it with 'net on'")
		else:
			# Disable networking somehow
			log.info("net", "Disabling network...")
			network.ENABLED = False

	elif command == "net on":
		if network.ENABLED:
			log.info("net", "Networking is already enabled. Disable it with 'net off'")
		else:
			# Re-Enable networking somehow
			log.info("net", "Enabling network...")
			network.ENABLED = True
			network.start_server()