Skip to content

Commit 8de2fb9

Browse files
author
yxq
committed
fix: set dht to server mode
1 parent 2da0889 commit 8de2fb9

File tree

2 files changed

+1
-19
lines changed

2 files changed

+1
-19
lines changed

system/p2p/dht/discovery.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func InitDhtDiscovery(ctx context.Context, host host.Host, peersInfo []peer.Addr
3939
//如果不修改DHTProto 则有可能会连入IPFS网络,dhtproto=/ipfs/kad/1.0.0
4040
d := new(Discovery)
4141

42-
kademliaDHT, err := dht.New(ctx, host, dht.V1ProtocolOverride(protocol.ID(fmt.Sprintf(dhtProtoID, chainCfg.GetTitle(), subCfg.Channel))), dht.BootstrapPeers(peersInfo...), dht.DisableAutoRefresh())
42+
kademliaDHT, err := dht.New(ctx, host, dht.V1ProtocolOverride(protocol.ID(fmt.Sprintf(dhtProtoID, chainCfg.GetTitle(), subCfg.Channel))), dht.BootstrapPeers(peersInfo...), dht.RoutingTableRefreshPeriod(time.Minute), dht.Mode(dht.ModeServer))
4343
if err != nil {
4444
panic(err)
4545
}

system/p2p/dht/protocol/p2pstore/refresh.go

-18
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package p2pstore
22

33
import (
4-
"context"
54
"encoding/hex"
65
"time"
76

87
"github.com/33cn/chain33/types"
9-
"github.com/libp2p/go-libp2p-core/peer"
108
kbt "github.com/libp2p/go-libp2p-kbucket"
119
)
1210

@@ -105,9 +103,6 @@ func (p *Protocol) updateExtendRoutingTable() {
105103
continue
106104
}
107105
_, _ = tmpRoutingTable.TryAddPeer(cPid, true, true)
108-
if len(p.Host.Network().Conns()) < 50 && len(p.Host.Network().ConnsToPeer(cPid)) == 0 {
109-
p.connect(cPid)
110-
}
111106
}
112107
}
113108

@@ -120,16 +115,3 @@ func (p *Protocol) updateExtendRoutingTable() {
120115
_ = tmpRoutingTable.Close()
121116
log.Info("updateExtendRoutingTable", "pid", p.Host.ID(), "local peers count", p.RoutingTable.Size(), "extendRoutingTable peer count", p.extendRoutingTable.Size(), "time cost", time.Since(start))
122117
}
123-
124-
func (p *Protocol) connect(pid peer.ID) {
125-
ctx, cancel := context.WithTimeout(p.Ctx, 3*time.Second)
126-
defer cancel()
127-
info := peer.AddrInfo{
128-
ID: pid,
129-
Addrs: p.Host.Peerstore().Addrs(pid),
130-
}
131-
if err := p.Host.Connect(ctx, info); err != nil {
132-
log.Error("Host Connect", "err", err, "peer", info.ID)
133-
}
134-
135-
}

0 commit comments

Comments
 (0)