-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper_startup.py
More file actions
155 lines (140 loc) · 7.13 KB
/
Copy pathhelper_startup.py
File metadata and controls
155 lines (140 loc) · 7.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
"""Helper Start performs all the startup operations."""
import ConfigParser
from bmconfigparser import BMConfigParser
import defaults
import sys
import os
import platform
from distutils.version import StrictVersion
from namecoin import ensureNamecoinOptions
import paths
import state
import helper_random
StoreConfigFilesInSameDirectoryAsProgramByDefault = False
# The user may de-select Portable Mode in the settings if they want the config
# files to stay in the application data folder.
def _loadTrustedPeer():
try:
trustedPeer = BMConfigParser().get('bitmessagesettings', 'trustedpeer')
except ConfigParser.Error:
# This probably means the trusted peer wasn't specified so we
# can just leave it as None
return
host, port = trustedPeer.split(':')
state.trustedPeer = state.Peer(host, int(port))
def loadConfig():
if state.appdata:
BMConfigParser().read(state.appdata + 'keys.dat')
# state.appdata must have been specified as a startup option.
try:
BMConfigParser().get('bitmessagesettings', 'settingsversion')
print 'Loading config files from directory specified on startup: ' + state.appdata
needToCreateKeysFile = False
except Exception:
needToCreateKeysFile = True
else:
BMConfigParser().read(paths.lookupExeFolder() + 'keys.dat')
try:
BMConfigParser().get('bitmessagesettings', 'settingsversion')
print 'Loading config files from same directory as program.'
needToCreateKeysFile = False
state.appdata = paths.lookupExeFolder()
except Exception:
# Could not load the keys.dat file in the program directory.
# Perhaps it is in the appdata directory.
state.appdata = paths.lookupAppdataFolder()
BMConfigParser().read(state.appdata + 'keys.dat')
try:
BMConfigParser().get('bitmessagesettings', 'settingsversion')
print 'Loading existing config files from', state.appdata
needToCreateKeysFile = False
except Exception:
needToCreateKeysFile = True
if needToCreateKeysFile:
# This appears to be the first time running the program; there is
# no config file (or it cannot be accessed). Create config file.
BMConfigParser().add_section('bitmessagesettings')
BMConfigParser().set('bitmessagesettings', 'settingsversion', '10')
BMConfigParser().set('bitmessagesettings', 'port', '8444')
BMConfigParser().set(
'bitmessagesettings', 'timeformat', '%%c')
BMConfigParser().set('bitmessagesettings', 'blackwhitelist', 'black')
BMConfigParser().set('bitmessagesettings', 'startonlogon', 'false')
if 'linux' in sys.platform:
BMConfigParser().set(
'bitmessagesettings', 'minimizetotray', 'false')
# This isn't implimented yet and when True on
# Ubuntu causes Bitmessage to disappear while
# running when minimized.
else:
BMConfigParser().set(
'bitmessagesettings', 'minimizetotray', 'true')
BMConfigParser().set(
'bitmessagesettings', 'showtraynotifications', 'true')
BMConfigParser().set('bitmessagesettings', 'startintray', 'false')
BMConfigParser().set('bitmessagesettings', 'socksproxytype', 'none')
BMConfigParser().set(
'bitmessagesettings', 'sockshostname', 'localhost')
BMConfigParser().set('bitmessagesettings', 'socksport', '9050')
BMConfigParser().set(
'bitmessagesettings', 'socksauthentication', 'false')
BMConfigParser().set(
'bitmessagesettings', 'sockslisten', 'false')
BMConfigParser().set('bitmessagesettings', 'socksusername', '')
BMConfigParser().set('bitmessagesettings', 'sockspassword', '')
BMConfigParser().set('bitmessagesettings', 'keysencrypted', 'false')
BMConfigParser().set(
'bitmessagesettings', 'messagesencrypted', 'false')
BMConfigParser().set('bitmessagesettings', 'defaultnoncetrialsperbyte', str(
defaults.networkDefaultProofOfWorkNonceTrialsPerByte))
BMConfigParser().set('bitmessagesettings', 'defaultpayloadlengthextrabytes', str(
defaults.networkDefaultPayloadLengthExtraBytes))
BMConfigParser().set('bitmessagesettings', 'minimizeonclose', 'false')
BMConfigParser().set(
'bitmessagesettings', 'maxacceptablenoncetrialsperbyte', '0')
BMConfigParser().set(
'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes', '0')
BMConfigParser().set('bitmessagesettings', 'dontconnect', 'true')
BMConfigParser().set('bitmessagesettings', 'userlocale', 'system')
BMConfigParser().set('bitmessagesettings', 'useidenticons', 'True')
BMConfigParser().set('bitmessagesettings', 'identiconsuffix', ''.join(helper_random.randomchoice("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz") for x in range(12)))# a twelve character pseudo-password to salt the identicons
BMConfigParser().set('bitmessagesettings', 'replybelow', 'False')
BMConfigParser().set('bitmessagesettings', 'maxdownloadrate', '0')
BMConfigParser().set('bitmessagesettings', 'maxuploadrate', '0')
BMConfigParser().set('bitmessagesettings', 'maxoutboundconnections', '8')
BMConfigParser().set('bitmessagesettings', 'ttl', '367200')
#start:UI setting to stop trying to send messages after X days/months
BMConfigParser().set(
'bitmessagesettings', 'stopresendingafterxdays', '')
BMConfigParser().set(
'bitmessagesettings', 'stopresendingafterxmonths', '')
#BMConfigParser().set(
# 'bitmessagesettings', 'timeperiod', '-1')
#end
# Are you hoping to add a new option to the keys.dat file? You're in
# the right place for adding it to users who install the software for
# the first time. But you must also add it to the keys.dat file of
# existing users. To do that, search the class_sqlThread.py file for the
# text: "right above this line!"
ensureNamecoinOptions()
if StoreConfigFilesInSameDirectoryAsProgramByDefault:
# Just use the same directory as the program and forget about
# the appdata folder
state.appdata = ''
print 'Creating new config files in same directory as program.'
else:
print 'Creating new config files in', state.appdata
if not os.path.exists(state.appdata):
os.makedirs(state.appdata)
if not sys.platform.startswith('win'):
os.umask(0o077)
BMConfigParser().save()
_loadTrustedPeer()
def isOurOperatingSystemLimitedToHavingVeryFewHalfOpenConnections():
try:
if sys.platform[0:3] == "win":
VER_THIS = StrictVersion(platform.version())
return StrictVersion("5.1.2600")<=VER_THIS and StrictVersion("6.0.6000")>=VER_THIS
return False
except Exception:
return False