示例#1
0
class Screen_manager(ScreenManager):
    def __init__(self, home, **kwargs):
        super().__init__(**kwargs)
        self.peer = None
        self.is_root = False
        self.address = None
        self.root_address = None
        self.home = home

    def print(self, s):
        print(s)

    def set_is_root(self, input):
        self.is_root = input

    def set_address(self, ip, port):
        self.address = Node.parse_address((ip, port))
        print(self.address)

    def set_root_address(self, ip, port):
        self.root_address = Node.parse_address((ip, port))
        print(self.root_address)

    def start_peer(self):
        self.peer = Peer(self.address[0], self.address[1], self.is_root, self,
                         self.root_address)
        self.peer.setDaemon(True)
        self.peer.start()

    def set(self):
        self.home.timer = '0'
        self.home.ip = self.address[0]
        self.home.port = self.address[1]
        if self.is_root:
            self.home.root_client = 'Root'
        else:
            self.home.root_client = 'Client'

        self.home.first_build()
        self.home.peer = self.peer
        self.home.update_stats()

    def display_message(self, message):
        self.home.display_message(message)

    def display_pkt(self, pkt):
        self.home.display_pkt(pkt)
        print('header: ')
        print(pkt.get_header())
        print('body: ')
        print(str(pkt.get_body()))

    def update_stats(self):
        self.home.update_stats()
示例#2
0
class UI:
    def __init__(self):
        print('enter ip and port')
        ip = input()
        port = input()
        print("wich one? A f*****g root or an asshole client?")
        s = input()
        if s == 'root':
            self.isRoot = True
            self.peer = Peer(ip, int(port), self.isRoot, self)
        else:
            self.isRoot = False
            print('enter server ip and port')
            rootIP = input()
            rootPort = input()
            self.peer = Peer(ip, int(port), self.isRoot, self,
                             (rootIP, rootPort))

        self.peer_buffer = self.peer.ui_buffer
        self.peer.start()
        self.reader = InputReader(self)
        self.reader.start()

    def display_message(self, message):
        print(message)

    def display_pkt(self, pkt):
        print('header: ')
        print(pkt.get_header())
        print('body: ')
        print(str(pkt.get_body()))

    def print_header(self, header):
        print('from')
        print(header[0])
        print(header[1])

    def add_to_buffer(self, shit):
        self.peer.add_command(shit)