Home | Trees | Indices | Help |
|
---|
|
1 """ 2 Handles communication with G4DS communication plattform. 3 4 Inter-Organisational Intrusion Detection System (IOIDS) 5 6 @author: Michael Pilgermann 7 @contact: mailto:mpilgerm@glam.ac.uk 8 @license: GPL (General Public License) 9 """ 10 11 # "singleton" 12 _g4dsConnector = None14 """ 15 Singleton implementation. 16 """ 17 global _g4dsConnector 18 if not _g4dsConnector: 19 _g4dsConnector = G4dsConnector() 20 return _g4dsConnector212397 98 99 # "singleton" 100 _dispatcher = None25 """ 26 Initialises local variables. 27 28 Perform the connection with L{connect}. Please shut down properly the connection with 29 L{disconnect}. 30 """ 31 from config import LOCATION_PRIVATE_KEY 32 self._locationKey = LOCATION_PRIVATE_KEY33 3436 """ 37 Establishes the connection to the G4DS backend. 38 """ 39 from g4ds import g4dsservice 40 from config import G4DS_SERVICE_ID 41 from errorhandling import IoidsException 42 43 self._g4ds = g4dsservice.G4dsService() 44 try: 45 self._g4ds.connect(G4DS_SERVICE_ID, None, self._locationKey, callback = self._incomingMessageCallback) 46 except Exception, msg: 47 raise IoidsException('G4DS connection failed: %s' %(msg))4850 """ 51 Shuts down connection to G4DS. 52 """ 53 try: 54 self._g4ds.disconnect() 55 except Exception, msg: 56 from errorhandling import IoidsException 57 raise IoidsException('G4DS connection shutdown failed: %s' %(msg))5860 """ 61 Callback function for G4DS to receive messages from it. 62 """ 63 from g4ds import g4dsservice 64 ## import cPickle as pickle 65 ## from StringIO import StringIO 66 ## st = StringIO(data) 67 ## data = pickle.load(st) 68 #### print "Received (%s): %s" %(metadata[g4dsservice.METADATA_SENDERID], data) 69 70 print "Received sth from %s" %(metadata[g4dsservice.METADATA_SENDERID]) 71 getDispatcher().dispatch(data, metadata)7274 self.sendMessage(data, 'ioids.write.newevent', receiver)7577 """ 78 @param conditions: List of conditions; each item a list itself (attribute name | operator indicator | value) 79 @type conditions: C{List} of C{List} 80 """ 81 condXml = None # here we go 82 self.sendMessage(condXml, 'ioids.read.events', receiver)8385 """ 86 Testing - send it off to everybody in the service :) 87 """ 88 if not receiver: 89 from config import G4DS_SERVICE_ID 90 receiver = G4DS_SERVICE_ID 91 92 self._g4ds.sendMessage(receiver, None, data, action) 93 from ioidslogging import getDefaultLogger, G4DS_CONNECTOR_OUTGOING_MSG, G4DS_CONNECTOR_OUTGOING_MSG_DETAILS 94 getDefaultLogger().newMessage(G4DS_CONNECTOR_OUTGOING_MSG, 'G4DS Outgoing message: Passed new message to %s' %(receiver)) 95 getDefaultLogger().newMessage(G4DS_CONNECTOR_OUTGOING_MSG_DETAILS, '-- Outgoing message details: action is %s' %(action)) 96 getDefaultLogger().newMessage(G4DS_CONNECTOR_OUTGOING_MSG_DETAILS, '-- Outgoing message details: data size is %s' %(len(data)))102 """ 103 Singleton implementation. 104 105 @return: The instance for the Dispatcher 106 @rtype: L{Dispatcher} 107 """ 108 global _dispatcher 109 if not _dispatcher: 110 _dispatcher = Dispatcher() 111 return _dispatcher112114 120154122 """ 123 First instance for incoming messages. 124 """ 125 ## print "My meta data: %s" %metadata 126 from ioidslogging import getDefaultLogger, G4DS_CONNECTOR_INCOMING_MSG, G4DS_CONNECTOR_INCOMING_MSG_DETAILS 127 getDefaultLogger().newMessage(G4DS_CONNECTOR_INCOMING_MSG, 'G4DS Incoming message: Received data from %s | %s' %(metadata['senderid'], metadata['communityid'])) 128 getDefaultLogger().newMessage(G4DS_CONNECTOR_INCOMING_MSG_DETAILS, '-- G4DS Incoming message details: action is %s ' %(metadata['actionstring'])) 129 getDefaultLogger().newMessage(G4DS_CONNECTOR_INCOMING_MSG_DETAILS, '-- G4DS Incoming message details: data size is %s ' %(len(data))) 130 if metadata['actionstring'] == 'ioids.write.newevent': 131 self._incomingMessageNewIoidsEvent(data) 132 elif metadata['actionstring'] == 'ioids.read.events': 133 sender = metadata['senderid'] 134 community = metadata['communityid'] 135 self._replyToKnowledgeRequest(sender, community, data)136 137139 ioidsevent = None 140 relations = [] 141 142 from messagewrapper import getIoidsMessageWrapper 143 ioidsevent, relations = getIoidsMessageWrapper().unwrapFullIoidsEventMessage(data) 144 from dataengine import getDataEngine 145 getDataEngine().newIoidsEventFromRemote(ioidsevent , relations)146 147
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0beta1 on Thu Feb 7 11:06:05 2008 | http://epydoc.sourceforge.net |