#!/usr/bin/python2.7

from twisted.internet.protocol import Protocol
from twisted.internet.protocol import Factory
from twisted.internet import ssl, reactor

class SworbNet:
    def __init__(self):
        self.hashes = {} # dict of hashes->file handle
        self.connections = []
    def addHash(self, hash, handle):
        self.hashes[hash] = handle

class SworbMessaging(Protocol):
    def __init__(self, factory, snet=None):
        self.factory = factory
        self.snet = snet

    def connectionMade(self):
        self.transport.write("ID 1") # TODO send back our IDo
        self.factory.numProtocols += 1

    def connectionLost(self, reason):
        self.factory.numProtocols -= 1

    def dataReceived(self, data):
        str = data.split(" ")

        try:
            # Hash lookup
            if str[0] is "0":
                if self.snet.hashes[str[1]] is not None:
                    # sucessful lookup
                    self.transport.write("1")
                else:
                    self.transport.write("0")
                    # TODO ask other people we are connected to if they have it

            # File request
            if str[0] is "1":
                # TODO get file
                pass

        except:
            self.transport.write("ILLEGAL")

class SMFactory(Factory):
    def __init__(self, net):
        self.net = net
    def buildProtocol(self, addr):
        return SworbMessaging(self, snet=self.net)

if __name__ == "__main__":
    net = SworbNet()

    factory = SMFactory(net)

    reactor.listenSSL(8666, factory, ssl.DefaultOpenSSLContextFactory(
        'keys/server.key', 'keys/server.crt'))

    reactor.run()

@@ -151,16 +151,37 @@
 eactor%0A%0A
+import ConfigParser%0A%0A
 class Sw
@@ -267,16 +267,42 @@
  handle%0A
+        self.clients = %5B%5D%0A
         
@@ -356,24 +356,24 @@
 h, handle):%0A
-
         self
@@ -394,16 +394,85 @@
 = handle
+%0A    def addClient(self, client):%0A        self.clients.append(client)
 %0A%0Aclass 
@@ -1605,23 +1605,249 @@
     
-net = SworbNet(
+config = ConfigParser.RawConfigParser()%0A    config.read(%22sworbnet.cfg%22)%0A%0A    clients = config.get(%22clients%22, %22clients%22).split(%22,%22)%0A    port = config.getint(%22server%22, %22port%22)%0A    net = SworbNet()%0A%0A    for c in clients:%0A        net.addClient(c
 )%0A%0A 
@@ -1901,12 +1901,12 @@
 SSL(
-8666
+port
 , fa

Add config file support