Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
36 kaklik 1
product_name = 'BitTornado'
2
version_short = 'T-0.3.15'
3
 
4
version = version_short+' ('+product_name+')'
5
report_email = version_short+'@degreez.net'
6
 
7
from types import StringType
8
from sha import sha
9
from time import time, clock
10
try:
11
    from os import getpid
12
except ImportError:
13
    def getpid():
14
        return 1
15
 
16
mapbase64 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-'
17
 
18
_idprefix = version_short[0]
19
for subver in version_short[2:].split('.'):
20
    try:
21
        subver = int(subver)
22
    except:
23
        subver = 0
24
    _idprefix += mapbase64[subver]
25
_idprefix += ('-' * (6-len(_idprefix)))
26
_idrandom = [None]
27
 
28
def resetPeerIDs():
29
    try:
30
        f = open('/dev/urandom','rb')
31
        x = f.read(20)
32
        f.close()
33
    except:
34
        x = ''
35
 
36
    l1 = 0
37
    t = clock()
38
    while t == clock():
39
        l1 += 1
40
    l2 = 0
41
    t = long(time()*100)
42
    while t == long(time()*100):
43
        l2 += 1
44
    l3 = 0
45
    if l2 < 1000:
46
        t = long(time()*10)
47
        while t == long(clock()*10):
48
            l3 += 1
49
    x += ( repr(time()) + '/' + str(time()) + '/'
50
           + str(l1) + '/' + str(l2) + '/' + str(l3) + '/'
51
           + str(getpid()) )
52
 
53
    s = ''
54
    for i in sha(x).digest()[-11:]:
55
        s += mapbase64[ord(i) & 0x3F]
56
    _idrandom[0] = s
57
 
58
resetPeerIDs()
59
 
60
def createPeerID(ins = '---'):
61
    assert type(ins) is StringType
62
    assert len(ins) == 3
63
    return _idprefix + ins + _idrandom[0]