Exemple #1
0
 def handle_yo_message(self, message, address):
     # insert the new peer into our peerlist
     try:
         peer = find_peer_by_address(address)
     except PeerNotFoundException:
         new_peer = Peer(address)
         new_peer.tcp_port = message.port
         new_peer.alias = message.username
         peerlist.append(new_peer)
     else:
         peer.last_seen = datetime.now()
Exemple #2
0
    def handle_hi_message(self, message, address):
        # insert the new peer into our peerlist
        try:
            peer = find_peer_by_address(address)
        except PeerNotFoundException:
            new_peer = Peer(address)
            new_peer.tcp_port = message.port
            new_peer.alias = message.username
            peerlist.append(new_peer)
        else:
            peer.last_seen = datetime.now()

        # prepare a yo, but only if the hi did not come from myself
        if address not in settings.OWN_IP_ADDRESSES:
            yo = YoMessage(peerlist.self_peer.tcp_port,
                peerlist.self_peer.alias)
            self.send_message_to_multicast_group(yo)
Exemple #3
0
import gevent
from gevent import socket
from gevent.server import StreamServer, DatagramServer
from gevent import Greenlet

import settings
import datagram
from connection import handle_connection
from ui import run_ui
from peerlist import Peer, AvailableFile, share_files_from_folder
from peerlist import decrement_other_peers_files_ttl, peerlist

peerlist.self_peer = Peer(settings.LOOPBACK_IP_ADDRESS)
peerlist.self_peer.tcp_port = settings.TCP_PORT
peerlist.self_peer.alias = settings.ALIAS
peerlist.append(peerlist.self_peer)


# build own file list
for s in settings.SHARE:
    share_files_from_folder(s)


# decrement the TTL of all other peer's files every second
Greenlet.spawn(decrement_other_peers_files_ttl)

# On Linux, binding TCP to in6addr_any will also listen on IPv4
connection_server = StreamServer((settings.IPV6_BIND_INTERFACE, settings.TCP_PORT), handle_connection)
connection_server.family = socket.AF_INET6
connection_server.init_socket()
connection_server.start()