NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

SessionChangeGPCS.py (6656B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\carbon\common\script\net\SessionChangeGPCS.py
      2 import copy
      3 import numbers
      4 import types
      5 import log
      6 from carbon.common.script.net import machoNet, machoNetAddress, machoNetPacket
      7 from cluster import MACHONETMSG_TYPE_SESSIONCHANGENOTIFICATION, MACHONETMSG_TYPE_SESSIONINITIALSTATENOTIFICATION
      8 
      9 class SessionChange:
     10     __guid__ = 'gpcs.SessionChange'
     11 
     12     def NotifyUp(self, packet):
     13         if packet.command == MACHONETMSG_TYPE_SESSIONCHANGENOTIFICATION:
     14             nodesOfInterest = None
     15             if machoNet.mode == 'proxy':
     16                 nodesOfInterest = getattr(packet, 'nodesOfInterest', None)
     17                 transport = self.machoNet.GetMachoTransportByClientID(packet.source.clientID)
     18                 if transport is not None:
     19                     if nodesOfInterest is None or -1 in nodesOfInterest:
     20                         if nodesOfInterest is None:
     21                             nodesOfInterest = []
     22                         for each in self.machoNet.GetMachoTransportsByTransportIDs(transport.dependants.iterkeys()):
     23                             if each.nodeID not in nodesOfInterest:
     24                                 nodesOfInterest.append(each.nodeID)
     25 
     26             if not getattr(session, 'clientID', 0) and machoNet.mode != 'client':
     27                 self.machoNet.LogError('Received a session change notification on a non-client session')
     28                 self.machoNet.LogError('Packet=', packet)
     29                 log.LogTraceback()
     30                 session.DumpSession('NONCLIENT', 'Session change notification received on non-client session')
     31             else:
     32                 session.ApplyRemoteAttributeChanges(packet.change[1], initialState=False)
     33             if machoNet.mode == 'proxy' and packet.source.clientID != getattr(session, 'clientID', 0):
     34                 self.machoNet.LogError("Session change notification - clientID doesn't match in packet and session")
     35                 self.machoNet.LogError('packet: ', packet.source.clientID, ' details=', packet)
     36                 self.machoNet.LogError('session: ', getattr(session, 'clientID', 0), ' details=', session)
     37             if getattr(session, 'clientID', 0) and machoNet.mode == 'proxy':
     38                 if transport is None:
     39                     self.machoNet.LogWarn('Transport is None in session change, nodesOfInterest is ', nodesOfInterest)
     40                     self.machoNet.LogWarn('session = ', session)
     41                 elif nodesOfInterest is not None:
     42                     sessionVersion = session.version + 1
     43                     self.machoNet.LogInfo('SessionChangeGPCS: session(', session.sid, ")'s new version number is ", session.version, ' we have ', len(nodesOfInterest), ' noi')
     44                     for each in nodesOfInterest:
     45                         if each != packet.destination.nodeID and each != -1:
     46                             transportOfNode = self.machoNet.GetTransportOfNode(each)
     47                             transportIsKnown = transportOfNode.transportID in transport.dependants
     48                             if transportIsKnown:
     49                                 transportVersion = transport.dependants[transportOfNode.transportID]
     50                             if not transportIsKnown:
     51                                 sessionprops = {}
     52                                 for v in session.GetDistributedProps(0):
     53                                     sessionprops[v] = getattr(session, v)
     54 
     55                                 self.ForwardNotifyDown(machoNetPacket.SessionInitialStateNotification(source=machoNetAddress.MachoAddress(clientID=session.clientID), destination=machoNetAddress.MachoAddress(nodeID=each), sid=session.sid, sessionType=session.sessionType, initialstate=sessionprops))
     56                             elif sessionVersion > transportVersion:
     57                                 change = {}
     58                                 for v in session.GetDistributedProps(1):
     59                                     change[v] = (None, getattr(session, v))
     60 
     61                                 self.ForwardNotifyDown(machoNetPacket.SessionChangeNotification(source=machoNetAddress.MachoAddress(clientID=session.clientID), destination=machoNetAddress.MachoAddress(nodeID=each), sid=session.sid, change=(1, change)))
     62 
     63             if machoNet.mode == 'proxy':
     64                 packet.source, packet.destination = packet.destination, packet.source
     65                 self.ForwardNotifyDown(packet)
     66         elif packet.command == MACHONETMSG_TYPE_SESSIONINITIALSTATENOTIFICATION:
     67             if not getattr(session, 'clientID', 0) and machoNet.mode != 'client':
     68                 self.machoNet.LogError('Received a session initial state notification on a non-client session')
     69                 self.machoNet.LogError('Packet=', packet)
     70                 log.LogTraceback()
     71             else:
     72                 session.ApplyRemoteAttributeChanges(packet.initialstate, initialState=True)
     73 
     74     def SessionChanged(self, clientID, sid, change, nodesOfInterest = None):
     75         if nodesOfInterest:
     76             tmp = []
     77             for each in nodesOfInterest:
     78                 if type(each) == types.ListType or type(each) == types.TupleType:
     79                     for other in each:
     80                         if other and other not in tmp:
     81                             tmp.append(other)
     82 
     83                 elif isinstance(each, numbers.Integral) and each not in tmp:
     84                     tmp.append(each)
     85 
     86             nodesOfInterest = tmp
     87         packet = machoNetPacket.SessionChangeNotification(destination=machoNetAddress.MachoAddress(clientID=clientID), sid=sid, change=(0, change), nodesOfInterest=nodesOfInterest)
     88         if machoNet.mode == 'proxy':
     89             transport = self.machoNet.GetMachoTransportByClientID(clientID)
     90             if transport is not None:
     91                 nodesOfInterest = getattr(packet, 'nodesOfInterest', None)
     92                 if nodesOfInterest is None or -1 in nodesOfInterest:
     93                     if nodesOfInterest is None:
     94                         nodesOfInterest = []
     95                     for each in self.machoNet.GetMachoTransportsByTransportIDs(transport.dependants.iterkeys()):
     96                         if each.nodeID not in nodesOfInterest:
     97                             nodesOfInterest.append(each.nodeID)
     98 
     99                 for each in nodesOfInterest:
    100                     if each != -1:
    101                         c = copy.copy(packet)
    102                         c.source = machoNetAddress.MachoAddress(clientID=clientID)
    103                         c.destination = machoNetAddress.MachoAddress(nodeID=each)
    104                         self.ForwardNotifyDown(c)
    105 
    106         self.ForwardNotifyDown(packet)