def __init__(self, protoPathList, mesgHandle, excludeProtos, sourceId, isClient=True): cmd.Cmd.__init__(self) PeaView.__init__(self, protoPathList, mesgHandle, excludeProtos, sourceId, 0) # print self.messageDict.nameDict import functools for mesgName in self.messageDict.nameDict.keys(): mesgName1 = mesgName.split(':')[0] setattr(Peagun, 'do_' + mesgName1, functools.partial(self.requestCommon, mesgName)) setattr(Peagun, 'do_setpeeradd', self.do_setPeerAddress) self.connectParamPattern = re.compile( '(\w+|(?:\d+\.){3}(?:\d+))\s+(\d+)') self.historyLoaded = False self.setPattern = re.compile('(\w+)\s*=\s*(\$[\w?%]+|\w+:\w*)') self.isExited = False import threading self.messageCond = threading.Condition() self.waitMessageId = -1 self.isClient = isClient self.ignoreMessages = [0, 17] self.sessionId = 0
def __init__(self, protoPathList, mesgHandle, excludeProtos, sourceId, isClient = True): cmd.Cmd.__init__(self) PeaView.__init__(self, protoPathList, mesgHandle, excludeProtos, sourceId, 0) # print self.messageDict.nameDict import functools for mesgName in self.messageDict.nameDict.keys(): mesgName1 = mesgName.split(':')[0] setattr(Peagun, 'do_' + mesgName1, functools.partial(self.requestCommon, mesgName)) setattr(Peagun, 'do_setpeeradd', self.do_setPeerAddress) self.connectParamPattern = re.compile('(\w+|(?:\d+\.){3}(?:\d+))\s+(\d+)') self.historyLoaded = False self.setPattern = re.compile('(\w+)\s*=\s*(\$[\w?%]+|\w+:\w*)') self.isExited = False import threading self.messageCond = threading.Condition() self.waitMessageId = -1 self.isClient = isClient self.ignoreMessages = [0,17] self.sessionId = 0
def __init__(self, protoPathList, metaPath, mesgHandle): cmd.Cmd.__init__(self) PeaView.__init__(self, protoPathList, metaPath, mesgHandle) self.connectParamPattern = re.compile( '(\w+|(?:\d+\.){3}(?:\d+))\s+(\d+)') self.historyLoaded = False self.setPattern = re.compile('(\w+)\s*=\s*(\$[\w?%]+|\w+:\w*)') self.deferredActions = [] self.isExited = False import virtkey self.keyboard = virtkey.virtkey()
print('thrift generating gen-py for proto files in dir:' + str(confs.ProtoPath)) try: metaPath = '/tmp/' sys.path.append(os.path.join(metaPath, 'gen-py')) generateProto(confs.ProtoPath, metaPath) except Exception as e: print('thrift generate gen-py failed: ' + str(e)) sys.exit(-1) print('thrift generate gen-py done') print('server initialzing...') try: server = PeaView(confs.ProtoPath, Factory.createMessageHandles(confs.PluginPaths), confs.ExcludeProtos, confs.SourceId, False) server.customHandle.load(confs) except Exception as e: print('server initialize failed,' + str(e)) sys.exit(-1) print('server initialize done.') def onConnected(connectionManager, proto): from aclSystem.ttypes import Session session = Session() session.sessionID = 100 session.userID = 8 session.appID = confs.SourceId session.AppGroupId = 2
print scriptPath configureFile = open(os.path.join(scriptPath, '../config.txt'), 'r') import json confs = json.load(configureFile) configureFile.close() metaPath = '/tmp' generateProto([confs['PATH']]) sys.path.append(metaPath + '/gen-py') sourceId = 605 pea = PeaView([confs['PATH']], Factory.createMessageHandles([]), ['LMFHFProto.thrift', 'PluginManage.thrift'], sourceId, requestId=0) def sendHeartbeat(pea, proto): reactor.callLater(30, sendHeartbeat, pea, proto) def test(pea, proto): client123 = ACLClient(proto, pea.customHandle, 609) session = client123.login('bb', '1232') client = SecClient(proto, pea.customHandle, 609) #两对密钥对
sourceId = 605 # import json # tableMappings = json.load(open('list2table.mapping','r')) # pea = PeaView([os.path.join(scriptPath, 'thrift')], Factory.createMessageHandles([pluginPath1, pluginPath2]),['LMFHFProto.thrift','PluginManage.thrift'], # sourceId, requestId=0) files = [ os.path.join(scriptPath, 'thrift', f) for f in os.listdir(os.path.join(scriptPath, 'thrift')) ] pea = PeaView([os.path.join(scriptPath, 'thrift')], Factory.createMessageHandles([]), ['LMFHFProto.thrift', 'PluginManage.thrift'], sourceId, requestId=0) def sendHeartbeat(pea, proto): #pea.sendHeartbeat(proto) reactor.callLater(30, sendHeartbeat, pea, proto) def test(pea, proto): client = ACLClient(proto, pea.customHandle, 609) session = client.login('bb', '1232') print 'login %s' % session
help= 'path(wildcard) to the plugin files which will be used as messages handle.' ) parser.add_argument('-r', '--protos', required=True, action='append', help='directory list which containing protocol files') parser.add_argument('-d', '--daemon', type=bool, default=False) args = parser.parse_args() metaPath = '/tmp' generateProto(args.protos) sys.path.append(metaPath + '/gen-py') if args.daemon: pea = PeaView(args.protos, metaPath, Factory.createMessageHandle(args.plugin)) if args.isClient: pea.connectionManager.connect(args.host, args.port) else: from twisted.internet.endpoints import serverFromString serverFromString( reactor, 'tcp:interface=%s:port=%d' % (args.host, args.port)).listen(pea.connectionManager) else: pea = Peagun(args.protos, metaPath, Factory.createMessageHandle(args.plugin)) if args.isClient: pea.cmdqueue.append('connect %s %d' % (args.host, args.port)) else: pea.cmdqueue.append('listen tcp:interface=%s:port=%d' % (args.host, args.port))
print('thrift generating gen-py for proto files in dir:' + str(confs.ProtoPath)) try: metaPath = '/tmp/' sys.path.append(os.path.join(metaPath, 'gen-py')) generateProto(confs.ProtoPath, metaPath) except Exception as e: print('thrift generate gen-py failed: ' + str(e)) sys.exit(-1) print('thrift generate gen-py done') print('server initialzing...') try: server = PeaView(confs.ProtoPath , Factory.createMessageHandles(confs.PluginPaths) , confs.ExcludeProtos , confs.SourceId , False) server.customHandle.load(confs) except Exception as e: print('server initialize failed,' + str(e)) sys.exit(-1) print('server initialize done.') def onConnected(connectionManager, proto): from aclSystem.ttypes import Session session = Session() session.sessionID = 100 session.userID = 8 session.appID = confs.SourceId