def createGate(self, gateAddrString, gatePort="default", serviceClass=Service): if gateAddrString in self.gates: return False if gatePort == "default": gatePort = self.gatePort g2gConnect = ConnectionData(self.chapAddr, self.chapPort, self.gatePort, gateAddrString) self.gates[gateAddrString] = self.gatePort self.gatePort += 1 self.logger = playgroundlog.LoggingContext("GATE_%s" % g2gConnect.playgroundAddr) serviceClass.Create(reactor, g2gConnect) return g2gConnect # return the "gate key" connection data
def _realStart(self, transmissions, **parameters): sys.path.insert(0, self.playgroundPath) import playground print "Starting test for", self.playgroundPath, playground import test_throughput_core as core from playground import playgroundlog logctx = playgroundlog.LoggingContext("peer_%s" % self.testId()) # Uncomment the next line to turn on "packet tracing" #logctx.doPacketTracing = True playgroundlog.startLogging(logctx) #playgroundlog.UseStdErrHandler(True) if self.stackName: print "importing stack", stackName try: exec("import " + self.stackName) except Exception, e: print "Failed to start because could not import stack", self.stackName, e return stack = eval(self.stackName)
''' Created on Sep 10, 2016 @author: sethjn ''' from playground import playgroundlog from playground.network.gate import Service, ConnectionData from playground.twisted.error.ErrorHandlers import TwistedShutdownErrorHandler from twisted.internet import reactor import sys if __name__ == "__main__": gateConfig = len(sys.argv) == 2 and sys.argv[1] or None g2gConnect = ConnectionData.CreateFromConfig(gateConfig) logctx = playgroundlog.LoggingContext("GATE_%s" % g2gConnect.playgroundAddr) # Uncomment the next line to turn on "packet tracing" #logctx.doPacketTracing = True playgroundlog.startLogging(logctx) playgroundlog.UseStdErrHandler(True) TwistedShutdownErrorHandler.HandleRootFatalErrors() Service.Create(reactor, gateConfig) reactor.run()
def connectionMade(self): higherTransport = PassThroughTransport(self.transport) self.makeHigherConnection(higherTransport) def dataReceived(self, data): self.storage.update(data) for msg in self.storage.iterateMessages(): #process msg ptMessage, bytesUsed = PassThroughMessage.Deserialize(data) data = ptMessage.data self.higherProtocol() and self.higherProtocol().dataReceived(data) class PassThroughFactory(StackingFactoryMixin, Factory): protocol = PassThroughProtocol # Turn on logging logctx = playgroundlog.LoggingContext("passThrough") # Uncomment the next line to turn on "packet tracing" #logctx.doPacketTracing = True playgroundlog.startLogging(logctx) playgroundlog.UseStdErrHandler(True) ConnectFactory = PassThroughFactory ListenFactory = PassThroughFactory
USAGE = """usage: echotest <mode> [<gatekey>] mode is either 'server' or a server's address (client mode)""" if __name__ == "__main__": echoArgs = sys.argv[1:] if len(echoArgs) == 1: mode = echoArgs[0] gateKey = None elif len(echoArgs) == 2: mode, gateKey = echoArgs else: sys.exit(USAGE) # Turn on logging logctx = playgroundlog.LoggingContext("echo_" + str(mode)) # Uncomment the next line to turn on "packet tracing" #logctx.doPacketTracing = True playgroundlog.startLogging(logctx) playgroundlog.UseStdErrHandler(True) # Set up the client base #client = ClientBase(myAddress) #serverAddress, serverPortString = sys.argv[1:3] #chaperonePort = 9090#int(serverPortString) if mode.lower() == "server": # This guy will be the server. Create an instance of the factory echoProtocolServer = EchoServer()
else: if self.verifySignedMessage(rMessage): logger.debug("RIPClient ERROR--Received unexpected SNN, moving to questioning state and closing connection") print "RIPClient ERROR--Received unexpected SNN, moving to questioning state and closing connection" self.higherTransport.state == "QUESTIONING" self.higherTransport.closeConnection() else: self.commonDataReceived(rMessage) else: logger.debug("RIPServer ERROR--Processsing data message of type %s", type(rMessage)) class RIPClientFactory(StackingFactoryMixin, Factory): protocol = RIPClient class RIPServerFactory(StackingFactoryMixin, Factory): protocol = RIPServer # Turn on logging logctx = playgroundlog.LoggingContext("RIP") # Uncomment the next line to turn on "packet tracing" #logctx.doPacketTracing = True #playgroundlog.startLogging(logctx) #playgroundlog.UseStdErrHandler(True) ConnectFactory = RIPClientFactory ListenFactory = RIPServerFactory
for arg in args: if arg.startswith("-"): k, v = arg.split("=") gstarArgs[k] = v else: gstarArgs[i] = arg i += 1 # Get the args you need chapAddr = gstarArgs.get("--cA", "127.0.0.1") chapPort = gstarArgs.get("--cP", "9090") gatesFile = gstarArgs.get("--gFile", None) # Do logging things logger = logging.getLogger(__name__) logctx = playgroundlog.LoggingContext("GATESTARTER_MAIN") # Uncomment the next line to turn on "packet tracing" #logctx.doPacketTracing = True playgroundlog.startLogging(logctx) playgroundlog.UseStdErrHandler(True) # Start the Gate Starter starter = GateStarter(logctx, chapAddr, chapPort, gatesFile) deferLater(reactor, .2, starter.reset) stdio.StandardIO(starter) TwistedShutdownErrorHandler.HandleRootFatalErrors() reactor.run()
def createLGService(gatekey=None, logger=None, chapAddr="127.0.0.1", chapPort="9090"): print("createLGService() called: %s" % chapAddr) g2gConnect = ConnectionData(chapAddr, chapPort, 19090, "1.1.1.1") return LGService.Create(reactor, g2gConnect).grabber if __name__ == "__main__": args = sys.argv[1:] if len(args) > 0: chapAddr = args[0] else: chapAddr = "127.0.0.1" if len(args) > 1: chapPort = args[1] else: chapPort = "9090" # Do logging things logctx = playgroundlog.LoggingContext("GATE_MAIN") # Uncomment the next line to turn on "packet tracing" #logctx.doPacketTracing = True playgroundlog.startLogging(logctx) playgroundlog.UseStdErrHandler(True) TwistedShutdownErrorHandler.HandleRootFatalErrors() createLGService(chapAddr=chapAddr, chapPort=chapPort).isMain = True deferLater(reactor, .75, reactor.stop) reactor.run()