old_contents: from twisted.application import service
  
  
  class SNPService(service.Service):
  
      def handleRequest(self, request, reqid, protocol):
          if "Type" in request:
              reqtype = request["Type"]
              thunk = getattr(self, 'type_%s' % reqtype.lower(), None)
              if thunk is None:
                  return
              try:
                  thunk(request, reqid, protocol)
              except:
                  return
  
      def connectionMade(self, protocol):
          pass
  
      def clientConnectionFailed(self, connector, reason):
          pass
  
new_contents: from twisted.application import service
  
  
  class SNPService(service.Service):
  
      def __init__(self):
          self.peers = {}
  
      def handleRequest(self, request, reqid, protocol):
          ip = protocol.transport.getPeer().host
          if "Type" in request:
              reqtype = request["Type"]
              if ip in self.peers or reqtype=="WEL" or reqtype == "AUR":
                  thunk = getattr(self, 'type_%s' % reqtype.lower(), None)
                  if thunk is None:
                      return
                  try:
                      thunk(request, reqid, protocol)
                  except:
                      return
              else:
                  protocol.sendError(1, request)
  
      def connectionMade(self, protocol):
          pass
  
      def clientConnectionFailed(self, connector, reason):
          pass
  
subject: Check in SNPService if connection intialized