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

machobase.py (3409B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\carbon\common\script\net\machobase.py
      2 import sys
      3 import types
      4 from hashlib import sha1
      5 import blue
      6 import carbon.common.script.net.GPSExceptions as GPS
      7 import eve.common.script.net.eveMachoNetVersion as eveMachoNetVersion
      8 import locks
      9 import log
     10 from carbon.common.lib import const
     11 from cluster import MACHONETMSG_TYPE_SESSIONCHANGENOTIFICATION, MACHONETMSG_TYPE_SESSIONINITIALSTATENOTIFICATION
     12 from eveprefs import boot
     13 from stringutil import strx
     14 mode = boot.role
     15 version = eveMachoNetVersion.machoVersion
     16 packetTypeChannelMap = {MACHONETMSG_TYPE_SESSIONCHANGENOTIFICATION: 'sessionchange',
     17  MACHONETMSG_TYPE_SESSIONINITIALSTATENOTIFICATION: 'sessionchange'}
     18 
     19 def Dumps(packet):
     20     return blue.marshal.Save(packet, None)
     21 
     22 
     23 def Loads(packet):
     24     ret = blue.marshal.Load(packet, skipCrcCheck=True)
     25     if isinstance(ret, GPS.GPSTransportClosed):
     26         log.general.Log('Raising a GPSTransportClosed exception from remote')
     27         raise ret
     28     return ret
     29 
     30 
     31 def SanitizedGetObjectID(object):
     32     if type(object) == types.InstanceType:
     33         if not isinstance(object, Exception):
     34             return strx(object)
     35 
     36 
     37 def SanitizedParseObjectID(objectID):
     38     return objectID
     39 
     40 
     41 def DumpsSanitized(what):
     42     return blue.marshal.Save(what, SanitizedGetObjectID)
     43 
     44 
     45 def LoadsSanitized(what):
     46     ret = blue.marshal.Load(what, SanitizedParseObjectID)
     47     if isinstance(ret, GPS.GPSTransportClosed):
     48         log.general.Log('Raising a GPSTransportClosed exception from remote')
     49         raise ret
     50     return ret
     51 
     52 
     53 def PasswordHash(userName, password):
     54     unicodeUserName = userName.strip().encode('utf-16')[2:]
     55     unicodePassword = password.encode('utf-16')[2:]
     56     salt = buffer(unicodeUserName.lower())
     57     hash = sha1(buffer(unicodePassword) + salt)
     58     for i in xrange(1000):
     59         blue.pyos.BeNice()
     60         hash = sha1(buffer(hash.digest()) + salt)
     61 
     62     return hash.digest()
     63 
     64 
     65 def AssignLogName(obj):
     66     try:
     67         name = obj.__logname__
     68     except AttributeError:
     69         try:
     70             name = GetLogName(obj)
     71             setattr(obj, '__logname__', name)
     72         except Exception:
     73             pass
     74 
     75     return name
     76 
     77 
     78 def GetLogName(obj):
     79     try:
     80         if hasattr(obj, '__guid__'):
     81             name = obj.__guid__
     82             s = name.split('.')
     83             if len(s) > 1:
     84                 name = s[1]
     85         else:
     86             name = obj.__class__.__name__
     87     except:
     88         name = 'CrappyClass %s' % str(obj)
     89         sys.exc_clear()
     90 
     91     return name
     92 
     93 
     94 def ThrottledCall(key, boundMethod, *args):
     95     logger = sm.GetService('machoNet').LogInfo
     96     with locks.TempLock(key, locks.RLock) as t:
     97         if hasattr(t, 'result'):
     98             logger('No need to cross the wire for', key, 'found throttler result from', (blue.os.GetWallclockTime() - t.resultTime) / const.uSEC, 'microseconds ago:', repr(t.result)[:128])
     99             ret = t.result
    100             if t.nWaiting == 0:
    101                 logger('No more consumers, invalidating cached result', repr(t.result)[:128])
    102                 del t.result
    103         else:
    104             ret = boundMethod(*args)
    105             if t.nWaiting > 0:
    106                 t.result = ret
    107                 t.resultTime = blue.os.GetWallclockTime()
    108                 logger('Sharing result for call', key, 'at', t.resultTime, 'for', t.nWaiting, 'waiting threads:', repr(t.result)[:128])
    109     return ret