-
Notifications
You must be signed in to change notification settings - Fork 43
/
p2p.go
779 lines (722 loc) · 19 KB
/
p2p.go
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
package main
import (
"bufio"
"bytes"
"compress/zlib"
"encoding/base64"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"net"
"net/http"
"os"
"sort"
"strconv"
"time"
)
const p2pClientVersionString = "godaisy/0.2"
// Header for JSON messages we're sending
type p2pMsgHeader struct {
Root string `json:"root"`
Msg string `json:"msg"`
P2pID int64 `json:"p2p_id"`
}
// The hello message
const p2pMsgHello = "hello"
type p2pMsgHelloStruct struct {
p2pMsgHeader
Version string `json:"version"`
ChainHeight int `json:"chain_height"`
MyPeers []string `json:"my_peers"`
}
// The message asking for block hashes
const p2pMsgGetBlockHashes = "getblockhashes"
type p2pMsgGetBlockHashesStruct struct {
p2pMsgHeader
MinBlockHeight int `json:"min_block_height"`
MaxBlockHeight int `json:"max_block_height"`
}
// The message reporting block hashes a node has
const p2pMsgBlockHashes = "blockhashes"
type p2pMsgBlockHashesStruct struct {
p2pMsgHeader
Hashes map[int]string `json:"hashes"`
}
// The message asking for block data
const p2pMsgGetBlock = "getblock"
type p2pMsgGetBlockStruct struct {
p2pMsgHeader
Hash string `json:"hash"`
}
// The message containing one block's data
const p2pMsgBlock = "block"
type p2pMsgBlockStruct struct {
p2pMsgHeader
Hash string `json:"hash"`
HashSignature string `json:"hash_signature"`
Size int64 `json:"size"`
Encoding string `json:"encoding"`
Data string `json:"data"`
}
// Map of peer addresses, for easy set-like behaviour
type peerStringMap map[string]time.Time
var bootstrapPeers = peerStringMap{
"cosmos.ivoras.net:2017": time.Now(),
"fielder.ivoras.net:2017": time.Now(),
}
// The temporary ID of this node, using strong RNG
var p2pEphemeralID = randInt63() & 0xffffffffffff
// Everything useful describing one p2p connection
type p2pConnection struct {
conn net.Conn
address string // host:port
peer *bufio.ReadWriter
peerID int64
isConnectable bool // using the default port
testedConnectable bool // using the default port
chainHeight int
refreshTime time.Time
chanToPeer chan interface{} // structs go out
chanFromPeer chan StrIfMap // StrIfMaps go in
}
// A set of p2p connections
type p2pPeersSet struct {
peers map[*p2pConnection]time.Time
lock WithMutex // Warning: do not do any IO/network operations while holding this lock
}
// The global set of p2p connections. XXX: Singletons in Go?
var p2pPeers = p2pPeersSet{peers: make(map[*p2pConnection]time.Time)}
// Adds a p2p connections to the set of p2p connections
func (p *p2pPeersSet) Add(c *p2pConnection) {
p.lock.With(func() {
p.peers[c] = time.Now()
})
}
// Removes a p2p connection from the set of p2p connections
func (p *p2pPeersSet) Remove(c *p2pConnection) {
p.lock.With(func() {
delete(p.peers, c)
})
}
func (p *p2pPeersSet) HasAddress(address string) bool {
found := false
p.lock.With(func() {
for peer := range p.peers {
if peer.address == address {
found = true
break
}
}
})
return found
}
func (p *p2pPeersSet) GetAddresses(onlyConnectable bool) []string {
var addresses []string
p.lock.With(func() {
for peer := range p.peers {
if onlyConnectable && !peer.isConnectable {
continue
}
addresses = append(addresses, peer.address)
}
})
return addresses
}
func (p *p2pPeersSet) tryPeersConnectable() {
addressesToTry := map[string]string{}
p.lock.With(func() {
for peer := range p.peers {
if peer.testedConnectable || peer.isConnectable {
continue
}
host, port, err := splitAddress(peer.address)
if err != nil {
continue
}
if port == DefaultP2PPort {
// we're already connected to it
continue
}
address := fmt.Sprintf("%s:%d", host, DefaultP2PPort)
peer.testedConnectable = true
addressesToTry[peer.address] = address
}
})
for paddress, address := range addressesToTry {
conn, err := net.Dial("tcp", address)
if err != nil {
continue
}
p.lock.With(func() {
for peer := range p.peers {
if peer.address == paddress {
peer.isConnectable = true
}
}
})
err = conn.Close()
if err != nil {
log.Println(err)
}
}
}
func (p *p2pPeersSet) saveConnectablePeers() {
dbPeers := dbGetSavedPeers()
localAddresses := getLocalAddresses()
p.lock.With(func() {
for peer := range p.peers {
if !peer.isConnectable {
continue
}
host, _, err := splitAddress(peer.address)
if err != nil {
continue
}
canonicalAddress := fmt.Sprintf("%s:%d", host, DefaultP2PPort)
addr, err := net.ResolveTCPAddr("tcp", canonicalAddress)
if err != nil {
continue
}
if _, ok := dbPeers[addr.IP.String()]; ok {
// Already in db
continue
}
if inStrings(addr.String(), localAddresses) {
// Local interface
continue
}
log.Println("Detected canonical peer at", canonicalAddress)
dbSavePeer(canonicalAddress)
}
})
}
func p2pServer() {
serverAddress := ":" + strconv.Itoa(cfg.P2pPort)
l, err := net.Listen("tcp", serverAddress)
if err != nil {
log.Println("Cannot listen on", serverAddress)
log.Fatal(err)
}
defer func() {
err = l.Close()
if err != nil {
log.Fatalf("p2pServer l.Close: %v", err)
}
}()
log.Println("P2P listening on", serverAddress)
for {
conn, err := l.Accept()
if err != nil {
log.Println("Error accepting socket:", err)
sysEventChannel <- sysEventMessage{event: eventQuit}
return
}
if p2pCoordinator.badPeers.Has(conn.RemoteAddr().String()) {
log.Println("Ignoring bad peer", conn.RemoteAddr().String())
continue
}
p2pc, err := p2pSetupPeer(conn.RemoteAddr().String(), conn)
if err != nil {
log.Println("Error setting up peer", conn.RemoteAddr().String(), err)
continue
}
go p2pc.handleConnection()
}
}
func p2pClient() {
p2pCoordinator.connectDbPeers()
}
func (p2pc *p2pConnection) sendMsg(msg interface{}) error {
bmsg, err := json.Marshal(msg)
if err != nil {
return err
}
n, err := p2pc.peer.Write(bmsg)
if err != nil {
return err
}
if n != len(bmsg) {
return fmt.Errorf("didn't write entire message: %v vs %v", n, len(bmsg))
}
n, err = p2pc.peer.Write([]byte("\n"))
if err != nil {
return err
}
if n != 1 {
return errors.New("didn't write newline")
}
//log.Println("... successfully wrote", string(bmsg))
return p2pc.peer.Flush()
}
func (p2pc *p2pConnection) handleConnection() {
defer func() {
log.Println("Cleaning up connection", p2pc.address)
p2pPeers.Remove(p2pc)
err := p2pc.conn.Close()
if err != nil {
log.Printf("p2pc.conn.Close: %v", err)
}
log.Println("Finished cleaning up connection", p2pc.address)
}()
// Only store the IP address as the address.
// This must be done in the goroutine because resolving can block for a long time.
addr, err := net.ResolveTCPAddr("tcp", p2pc.address)
if err == nil {
p2pc.address = addr.String()
}
p2pc.peer = bufio.NewReadWriter(bufio.NewReader(p2pc.conn), bufio.NewWriter(p2pc.conn))
// XXX: the state machine shouldn't start by the listener sending something
// (security best practices)
helloMsg := p2pMsgHelloStruct{
p2pMsgHeader: p2pMsgHeader{
P2pID: p2pEphemeralID,
Root: chainParams.GenesisBlockHash,
Msg: p2pMsgHello,
},
Version: p2pClientVersionString,
ChainHeight: dbGetBlockchainHeight(),
MyPeers: p2pPeers.GetAddresses(true),
}
err = p2pc.sendMsg(helloMsg)
if err != nil {
log.Println(err)
return
}
log.Println("Handling connection", p2pc.address)
exit := false
go func() {
var line []byte
for {
line, err = p2pc.peer.ReadBytes('\n')
if err != nil {
log.Println("Error reading data from", p2pc.address, err)
p2pc.chanFromPeer <- StrIfMap{"_error": "Error reading data"}
break
}
var msg StrIfMap
err = json.Unmarshal(line, &msg)
if err != nil {
log.Println("Cannot parse JSON", strconv.QuoteToASCII(string(line)), "from", p2pc.address)
p2pc.chanFromPeer <- StrIfMap{"_error": "Cannot parse JSON"}
break
}
var root string
if root, err = msg.GetString("root"); err != nil {
log.Printf("Problem with chain root from %v: %v", p2pc.address, err)
p2pc.chanFromPeer <- StrIfMap{"_error": "Problem with chain root"}
break
}
if root != chainParams.GenesisBlockHash {
log.Printf("Received message from %v for a different chain than mine (%s vs %s). Ignoring.", p2pc.conn, root, chainParams.GenesisBlockHash)
continue
}
p2pc.chanFromPeer <- msg
}
log.Println("Shutting down receiver for", p2pc.address)
exit = true // In any case, if this goroutine exits, we want to shut down everything
}()
ticker := time.NewTicker(1 * time.Second)
defer ticker.Stop()
for !exit {
select {
case msg := <-p2pc.chanFromPeer:
// log.Printf("... chainFromPeer: %s: %s", p2pc.address, jsonifyWhatever(msg))
var _error string
if _error, err = msg.GetString("_error"); err == nil {
log.Printf("Fatal error from %v: %v", p2pc.address, _error)
exit = true
break
}
var cmd string
if cmd, err = msg.GetString("msg"); err != nil {
log.Printf("Error with msg from %v: %v", p2pc.address, err)
exit = true
break
}
switch cmd {
case p2pMsgHello:
p2pc.handleMsgHello(msg)
case p2pMsgGetBlockHashes:
p2pc.handleGetBlockHashes(msg)
case p2pMsgBlockHashes:
p2pc.handleBlockHashes(msg)
case p2pMsgGetBlock:
p2pc.handleGetBlock(msg)
case p2pMsgBlock:
p2pc.handleBlock(msg)
}
case msg := <-p2pc.chanToPeer:
err := p2pc.sendMsg(msg)
if err != nil {
log.Println("Error sending to peer:", err)
exit = true
}
case <-ticker.C:
// so the exit variable gets tested
continue
}
}
// The connection has been dismissed
}
func (p2pc *p2pConnection) handleMsgHello(msg StrIfMap) {
var ver string
var err error
if ver, err = msg.GetString("version"); err != nil {
log.Println(p2pc.conn, err)
return
}
if p2pc.chainHeight, err = msg.GetInt("chain_height"); err != nil {
log.Println(p2pc.conn, err)
return
}
if p2pc.peerID == 0 {
if p2pc.peerID, err = msg.GetInt64("p2p_id"); err != nil {
log.Println(p2pc.conn, err)
return
}
}
var remotePeers []string
if remotePeers, err = msg.GetStringList("my_peers"); err == nil {
p2pCtrlChannel <- p2pCtrlMessage{msgType: p2pCtrlConnectPeers, payload: remotePeers}
}
log.Printf("Hello from %v %s (%x) %d blocks", p2pc.address, ver, p2pc.peerID, p2pc.chainHeight)
// Check for duplicates
dup := false
p2pPeers.lock.With(func() {
for p := range p2pPeers.peers {
if p.peerID == p2pc.peerID && p != p2pc {
log.Printf("%v looks like a duplicate of %v (%x), dropping it.", p2pc.address, p.address, p2pc.peerID)
dup = true
return
}
}
})
if p2pc.peerID == p2pEphemeralID {
log.Printf("%v is apparently myself (%x). Dropping it.", p2pc.conn, p2pc.peerID)
dup = true
}
if dup {
p2pCoordinator.badPeers.Add(p2pc.address)
err = p2pc.conn.Close()
if err != nil {
log.Printf("p2pc.conn.Close: %v", err)
}
return
}
p2pc.refreshTime = time.Now()
if p2pc.chainHeight > dbGetBlockchainHeight() {
p2pCtrlChannel <- p2pCtrlMessage{msgType: p2pCtrlSearchForBlocks, payload: p2pc}
}
}
// Handle getblockhashes
func (p2pc *p2pConnection) handleGetBlockHashes(msg StrIfMap) {
var minBlockHeight int
var maxBlockHeight int
var err error
if minBlockHeight, err = msg.GetInt("min_block_height"); err != nil {
log.Println(p2pc.conn, err)
return
}
if maxBlockHeight, err = msg.GetInt("max_block_height"); err != nil {
log.Println(p2pc.conn, err)
return
}
log.Printf("*** Sending block hashes from %d to %d to %s", minBlockHeight, maxBlockHeight, p2pc.address)
respMsg := p2pMsgBlockHashesStruct{
p2pMsgHeader: p2pMsgHeader{
P2pID: p2pEphemeralID,
Root: chainParams.GenesisBlockHash,
Msg: p2pMsgBlockHashes,
},
Hashes: dbGetHeightHashes(minBlockHeight, maxBlockHeight),
}
p2pc.chanToPeer <- respMsg
}
// Handle receiving blockhashes
func (p2pc *p2pConnection) handleBlockHashes(msg StrIfMap) {
var hashes map[int]string
var err error
if hashes, err = msg.GetIntStringMap("hashes"); err != nil {
log.Println(p2pc.conn, err)
return
}
heights := make([]int, len(hashes))
n := 0
for h := range hashes {
heights[n] = h
n++
}
sort.Ints(heights)
log.Println("handleBlockHashes: got", jsonifyWhatever(heights))
for _, h := range heights {
if dbBlockHeightExists(h) {
log.Println("handleBlockHashes: already have block:", h)
if dbGetBlockHashByHeight(h) != hashes[h] {
log.Println("ERROR: Blockchain desynced: received block hash at height", h, "to be", hashes[h], "instead of", dbGetBlockHashByHeight(h))
return
}
continue
}
if p2pCoordinator.recentlyRequestedBlocks.TestAndSet(hashes[h]) {
continue
}
log.Println("Requesting block", hashes[h])
msg := p2pMsgGetBlockStruct{
p2pMsgHeader: p2pMsgHeader{
P2pID: p2pEphemeralID,
Root: chainParams.GenesisBlockHash,
Msg: p2pMsgGetBlock,
},
Hash: hashes[h],
}
p2pc.chanToPeer <- msg
}
}
// getblock: a request to transfer a block
func (p2pc *p2pConnection) handleGetBlock(msg StrIfMap) {
hash, err := msg.GetString("hash")
if err != nil {
log.Println(p2pc.conn, err)
return
}
dbb, err := dbGetBlock(hash)
if err != nil {
log.Println(p2pc.conn, err)
return
}
fileName := blockchainGetFilename(dbb.Height)
st, err := os.Stat(fileName)
if err != nil {
log.Println(err)
return
}
fileSize := st.Size()
var msgBlockEncoding, msgBlockData string
if cfg.p2pBlockInline {
f, err := os.Open(fileName)
if err != nil {
log.Println(err)
return
}
defer func() {
err = f.Close()
if err != nil {
log.Printf("handleGetBlock f.Close: %v", err)
}
}()
var zbuf bytes.Buffer
w := zlib.NewWriter(&zbuf)
written, err := io.Copy(w, f)
if err != nil {
log.Println(err)
return
}
if written != fileSize {
log.Println("Something broke when working with zlib:", written, "vs", fileSize)
return
}
err = w.Close()
if err != nil {
log.Panic(err)
}
msgBlockEncoding = "zlib-base64"
msgBlockData = base64.StdEncoding.EncodeToString(zbuf.Bytes())
} else {
msgBlockEncoding = "http"
msgBlockData = fmt.Sprintf("http://%s:%d/block/%d", getLocalAddresses()[0], cfg.httpPort, dbb.Height)
log.Println("*** Instructing the peer to get a block from", msgBlockData)
}
respMsg := p2pMsgBlockStruct{
p2pMsgHeader: p2pMsgHeader{
P2pID: p2pEphemeralID,
Root: chainParams.GenesisBlockHash,
Msg: p2pMsgBlock,
},
Hash: hash,
HashSignature: hex.EncodeToString(dbb.HashSignature),
Encoding: msgBlockEncoding,
Data: msgBlockData,
Size: fileSize,
}
p2pc.chanToPeer <- respMsg
log.Println("*** Sent block", hash, "to", p2pc.address)
}
// block: A block is received
func (p2pc *p2pConnection) handleBlock(msg StrIfMap) {
hash, err := msg.GetString("hash")
if err != nil {
log.Println(err)
return
}
hashSignature, err := msg.GetString("hash_signature")
if err != nil {
log.Println(err)
return
}
dataString, err := msg.GetString("data")
if err != nil {
log.Println(err)
return
}
if dbBlockHashExists(hash) {
log.Println("Replacing blocks not yet implemented")
return
}
fileSize, err := msg.GetInt64("size")
if err != nil {
log.Println(err)
}
var blockFile *os.File
encoding, err := msg.GetString("encoding")
if err != nil {
log.Printf("encoding: %v", err)
return
}
if encoding == "zlib-base64" {
zlibData, err := base64.StdEncoding.DecodeString(dataString)
if err != nil {
log.Println(err)
return
}
blockFile, err = ioutil.TempFile("", "daisy")
if err != nil {
log.Println(err)
return
}
defer func() {
err = blockFile.Close()
if err != nil {
log.Printf("handleBlock blockFile.Close: %v", err)
}
err = os.Remove(blockFile.Name())
if err != nil {
log.Printf("remove: %v", err)
}
}()
r, err := zlib.NewReader(bytes.NewReader(zlibData))
if err != nil {
log.Println(err)
return
}
defer func() {
err = r.Close()
if err != nil {
log.Printf("handleBlock r.Close: %v", err)
}
}()
written, err := io.Copy(blockFile, r)
if err != nil {
log.Println(err)
return
}
if written != fileSize {
log.Println("Error decoding block: sizes don't match:", written, "vs", fileSize)
return
}
} else if encoding == "http" {
log.Println("Getting block", hash, "from", dataString)
resp, err := http.Get(dataString)
if err != nil {
log.Println("Error receiving block at", dataString, err)
return
}
defer resp.Body.Close()
blockFile, err = ioutil.TempFile("", "daisy")
if err != nil {
log.Println("Error creating temp file", err)
return
}
written, err := io.Copy(blockFile, resp.Body)
if err != nil {
log.Println("Error saving block:", err)
blockFile.Close()
os.Remove(blockFile.Name())
return
}
if written != fileSize {
log.Println("Error decoding block: sizes don't match:", written, "vs", fileSize)
blockFile.Close()
os.Remove(blockFile.Name())
return
}
err = blockFile.Close()
if err != nil {
log.Printf("handleBlock blockFile.Close: %v", err)
}
defer func() {
err = os.Remove(blockFile.Name())
if err != nil {
log.Printf("remove: %v", err)
}
}()
} else {
log.Println("Unknown block encoding:", encoding)
return
}
blk, err := OpenBlockFile(blockFile.Name())
if err != nil {
log.Println("Error opening block file", p2pc.conn, err)
return
}
blk.HashSignature, err = hex.DecodeString(hashSignature)
if err != nil {
log.Println("Error decoding hash signature", p2pc.conn, err)
return
}
height, err := checkAcceptBlock(blk)
if err != nil {
log.Println("Cannot import block:", err)
return
}
blk.Height = height
blk.DbBlockchainBlock.TimeAccepted = time.Now()
err = blockchainCopyFile(blockFile.Name(), height)
if err != nil {
log.Println("Cannot copy block file:", err)
return
}
err = dbInsertBlock(blk.DbBlockchainBlock)
if err != nil {
log.Println("Cannot insert block:", err)
return
}
log.Println("Accepted block", blk.Hash, "at height", blk.Height)
blk.Close()
}
// Connect to a peer. Does everything except starting the handler goroutine.
// Checks if there already is a connection of this type.
func p2pConnectPeer(address string) (*p2pConnection, error) {
addr, err := net.ResolveTCPAddr("tcp", address)
if err != nil {
return nil, err
}
if p2pPeers.HasAddress(addr.String()) {
return nil, fmt.Errorf("Connection to %s already exists", addr.String())
}
localAddresses := getLocalAddresses()
if inStrings(addr.IP.String(), localAddresses) {
return nil, fmt.Errorf("Refusing to connect to myself at %s", addr.IP)
}
conn, err := net.Dial("tcp", address)
if err != nil {
log.Println("Error connecting to", address, err)
return nil, err
}
return p2pSetupPeer(address, conn)
}
// Creates the p2pConnection structure for the peer and adds it to the peer list.
// Does not start the handler goroutine.
func p2pSetupPeer(address string, conn net.Conn) (*p2pConnection, error) {
p2pc := p2pConnection{
conn: conn,
address: address,
chanToPeer: make(chan interface{}, 5),
chanFromPeer: make(chan StrIfMap, 5),
}
p2pPeers.Add(&p2pc)
return &p2pc, nil
}