@@ -110,6 +110,7 @@ func main() {
110
110
processArgs ()
111
111
initialize ()
112
112
run ()
113
+ shutdown ()
113
114
}
114
115
115
116
func processArgs () {
@@ -209,21 +210,6 @@ func initialize() {
209
210
MinimumAcceptedPOW : * argPoW ,
210
211
}
211
212
212
- if * mailServerMode {
213
- if len (msPassword ) == 0 {
214
- msPassword , err = console .Stdin .PromptPassword ("Please enter the Mail Server password: " )
215
- if err != nil {
216
- utils .Fatalf ("Failed to read Mail Server password: %s" , err )
217
- }
218
- }
219
-
220
- shh = whisper .New (cfg )
221
- shh .RegisterServer (& mailServer )
222
- mailServer .Init (shh , * argDBPath , msPassword , * argServerPoW )
223
- } else {
224
- shh = whisper .New (cfg )
225
- }
226
-
227
213
if * argPoW != whisper .DefaultMinimumPoW {
228
214
err := shh .SetMinimumPoW (* argPoW )
229
215
if err != nil {
@@ -265,6 +251,26 @@ func initialize() {
265
251
maxPeers = 800
266
252
}
267
253
254
+ _ , err = crand .Read (entropy [:])
255
+ if err != nil {
256
+ utils .Fatalf ("crypto/rand failed: %s" , err )
257
+ }
258
+
259
+ if * mailServerMode {
260
+ if len (msPassword ) == 0 {
261
+ msPassword , err = console .Stdin .PromptPassword ("Please enter the Mail Server password: " )
262
+ if err != nil {
263
+ utils .Fatalf ("Failed to read Mail Server password: %s" , err )
264
+ }
265
+ }
266
+
267
+ shh = whisper .New (cfg )
268
+ shh .RegisterServer (& mailServer )
269
+ mailServer .Init (shh , * argDBPath , msPassword , * argServerPoW )
270
+ } else {
271
+ shh = whisper .New (cfg )
272
+ }
273
+
268
274
server = & p2p.Server {
269
275
Config : p2p.Config {
270
276
PrivateKey : nodeid ,
@@ -278,17 +284,13 @@ func initialize() {
278
284
TrustedNodes : peers ,
279
285
},
280
286
}
281
-
282
- _ , err = crand .Read (entropy [:])
283
- if err != nil {
284
- utils .Fatalf ("crypto/rand failed: %s" , err )
285
- }
286
287
}
287
288
288
- func startServer () {
289
+ func startServer () error {
289
290
err := server .Start ()
290
291
if err != nil {
291
- utils .Fatalf ("Failed to start Whisper peer: %s." , err )
292
+ fmt .Printf ("Failed to start Whisper peer: %s." , err )
293
+ return err
292
294
}
293
295
294
296
fmt .Printf ("my public key: %s \n " , common .ToHex (crypto .FromECDSAPub (& asymKey .PublicKey )))
@@ -307,6 +309,7 @@ func startServer() {
307
309
if ! * forwarderMode {
308
310
fmt .Printf ("Please type the message. To quit type: '%s'\n " , quitCommand )
309
311
}
312
+ return nil
310
313
}
311
314
312
315
func isKeyValid (k * ecdsa.PublicKey ) bool {
@@ -420,8 +423,10 @@ func waitForConnection(timeout bool) {
420
423
}
421
424
422
425
func run () {
423
- defer mailServer .Close ()
424
- startServer ()
426
+ err := startServer ()
427
+ if err != nil {
428
+ return
429
+ }
425
430
defer server .Stop ()
426
431
shh .Start (nil )
427
432
defer shh .Stop ()
@@ -439,8 +444,11 @@ func run() {
439
444
} else {
440
445
sendLoop ()
441
446
}
447
+ }
442
448
449
+ func shutdown () {
443
450
close (done )
451
+ mailServer .Close ()
444
452
}
445
453
446
454
func sendLoop () {
0 commit comments