Skip to content

Commit 7e5cc08

Browse files
committed
cr fixes
1 parent f151882 commit 7e5cc08

File tree

6 files changed

+26
-30
lines changed

6 files changed

+26
-30
lines changed

network/hybridNetwork.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,18 @@ func NewHybridP2PNetwork(log logging.Logger, cfg config.Local, datadir string, p
4949
p2pcfg.IncomingConnectionsLimit = cfg.P2PHybridIncomingConnectionsLimit
5050
identityTracker := NewIdentityTracker()
5151

52-
var subnetMeshCreator MeshCreator = meshCreator
52+
var childNetMeshCreator MeshCreator = meshCreator
5353
var hybridMeshCreator MeshCreator = &noopMeshCreator{}
54-
_, isHybridMeshCreator := meshCreator.(*HybridRelayMeshCreator)
54+
_, isHybridMeshCreator := meshCreator.(*hybridRelayMeshCreator)
5555
if meshCreator == nil && cfg.IsHybridServer() || isHybridMeshCreator {
5656
// no mesh creator provided and this node is a listening/relaying node
5757
// then override and use hybrid relay meshing
5858
// or, if a hybrid relay meshing requested explicitly, do the same
59-
subnetMeshCreator = &noopMeshCreator{}
60-
hybridMeshCreator = &HybridRelayMeshCreator{}
59+
childNetMeshCreator = &noopMeshCreator{}
60+
hybridMeshCreator = &hybridRelayMeshCreator{}
6161
}
6262

63-
p2pnet, err := NewP2PNetwork(log, p2pcfg, datadir, phonebookAddresses, genesisInfo, nodeInfo, &identityOpts{tracker: identityTracker}, subnetMeshCreator)
63+
p2pnet, err := NewP2PNetwork(log, p2pcfg, datadir, phonebookAddresses, genesisInfo, nodeInfo, &identityOpts{tracker: identityTracker}, childNetMeshCreator)
6464
if err != nil {
6565
return nil, err
6666
}
@@ -69,7 +69,7 @@ func NewHybridP2PNetwork(log logging.Logger, cfg config.Local, datadir string, p
6969
tracker: identityTracker,
7070
scheme: NewIdentityChallengeScheme(NetIdentityDedupNames(cfg.PublicAddress, p2pnet.PeerID().String()), NetIdentitySigner(p2pnet.PeerIDSigner())),
7171
}
72-
wsnet, err := NewWebsocketNetwork(log, cfg, phonebookAddresses, genesisInfo, nodeInfo, &identOpts, subnetMeshCreator)
72+
wsnet, err := NewWebsocketNetwork(log, cfg, phonebookAddresses, genesisInfo, nodeInfo, &identOpts, childNetMeshCreator)
7373
if err != nil {
7474
return nil, err
7575
}

network/hybridNetwork_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func TestHybridNetwork_DuplicateConn(t *testing.T) {
4747

4848
relayCfg := cfg
4949
relayCfg.ForceRelayMessages = true
50-
netA, err := NewHybridP2PNetwork(log.With("node", "netA"), relayCfg, p2pKeyDir, nil, genesisInfo, &nopeNodeInfo{}, &BaseMeshCreator{})
50+
netA, err := NewHybridP2PNetwork(log.With("node", "netA"), relayCfg, p2pKeyDir, nil, genesisInfo, &nopeNodeInfo{}, &baseMeshCreator{})
5151
require.NoError(t, err)
5252

5353
err = netA.Start()
@@ -66,7 +66,7 @@ func TestHybridNetwork_DuplicateConn(t *testing.T) {
6666
relayCfg.NetAddress = addr
6767
relayCfg.PublicAddress = addr
6868
relayCfg.P2PHybridNetAddress = "127.0.0.1:0"
69-
netA, err = NewHybridP2PNetwork(log.With("node", "netA"), relayCfg, p2pKeyDir, nil, genesisInfo, &nopeNodeInfo{}, &BaseMeshCreator{})
69+
netA, err = NewHybridP2PNetwork(log.With("node", "netA"), relayCfg, p2pKeyDir, nil, genesisInfo, &nopeNodeInfo{}, &baseMeshCreator{})
7070
require.NoError(t, err)
7171

7272
err = netA.Start()
@@ -87,14 +87,14 @@ func TestHybridNetwork_DuplicateConn(t *testing.T) {
8787

8888
phoneBookAddresses := []string{multiAddrStr, addr}
8989

90-
netB, err := NewHybridP2PNetwork(log.With("node", "netB"), cfg, "", phoneBookAddresses, genesisInfo, &nopeNodeInfo{}, &BaseMeshCreator{})
90+
netB, err := NewHybridP2PNetwork(log.With("node", "netB"), cfg, "", phoneBookAddresses, genesisInfo, &nopeNodeInfo{}, &baseMeshCreator{})
9191
require.NoError(t, err)
9292
// for netB start the p2p network first
9393
err = netB.p2pNetwork.Start()
9494
require.NoError(t, err)
9595
defer netB.Stop()
9696

97-
netC, err := NewHybridP2PNetwork(log.With("node", "netC"), cfg, "", phoneBookAddresses, genesisInfo, &nopeNodeInfo{}, &BaseMeshCreator{})
97+
netC, err := NewHybridP2PNetwork(log.With("node", "netC"), cfg, "", phoneBookAddresses, genesisInfo, &nopeNodeInfo{}, &baseMeshCreator{})
9898
require.NoError(t, err)
9999
// for netC start the ws network first
100100
err = netC.wsNetwork.Start()
@@ -193,12 +193,12 @@ func TestHybridNetwork_ValidateConfig(t *testing.T) {
193193
cfg.P2PHybridNetAddress = ""
194194
genesisInfo := GenesisInfo{genesisID, "net"}
195195

196-
_, err := NewHybridP2PNetwork(logging.TestingLog(t), cfg, "", nil, genesisInfo, &nopeNodeInfo{}, &BaseMeshCreator{})
196+
_, err := NewHybridP2PNetwork(logging.TestingLog(t), cfg, "", nil, genesisInfo, &nopeNodeInfo{}, &baseMeshCreator{})
197197
require.ErrorContains(t, err, "both NetAddress and P2PHybridNetAddress")
198198

199199
cfg.NetAddress = ""
200200
cfg.P2PHybridNetAddress = ":0"
201-
_, err = NewHybridP2PNetwork(logging.TestingLog(t), cfg, "", nil, genesisInfo, &nopeNodeInfo{}, &BaseMeshCreator{})
201+
_, err = NewHybridP2PNetwork(logging.TestingLog(t), cfg, "", nil, genesisInfo, &nopeNodeInfo{}, &baseMeshCreator{})
202202
require.ErrorContains(t, err, "both NetAddress and P2PHybridNetAddress")
203203
}
204204

network/mesh.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -188,20 +188,19 @@ type MeshCreator interface {
188188
create(opts ...meshOption) (mesher, error)
189189
}
190190

191-
// BaseMeshCreator is a creator for the base mesh strategy used in our standard WS or P2P implementations:
191+
// baseMeshCreator is a creator for the base mesh strategy used in our standard WS or P2P implementations:
192192
// run a mesh thread that periodically checks for new peers.
193-
type BaseMeshCreator struct {
194-
}
193+
type baseMeshCreator struct{}
195194

196-
func (c *BaseMeshCreator) create(opts ...meshOption) (mesher, error) {
195+
func (c *baseMeshCreator) create(opts ...meshOption) (mesher, error) {
197196
return newBaseMesher(opts...)
198197
}
199198

200-
// HybridRelayMeshCreator is a creator for the hybrid relay mesh strategy used in hybrid relays:
199+
// hybridRelayMeshCreator is a creator for the hybrid relay mesh strategy used in hybrid relays:
201200
// always use wsnet nodes
202-
type HybridRelayMeshCreator struct{}
201+
type hybridRelayMeshCreator struct{}
203202

204-
func (c *HybridRelayMeshCreator) create(opts ...meshOption) (mesher, error) {
203+
func (c *hybridRelayMeshCreator) create(opts ...meshOption) (mesher, error) {
205204
var cfg meshConfig
206205
for _, opt := range opts {
207206
opt(&cfg)
@@ -214,9 +213,8 @@ func (c *HybridRelayMeshCreator) create(opts ...meshOption) (mesher, error) {
214213
out := make(chan meshRequest, 5)
215214
var wg sync.WaitGroup
216215

217-
creator := BaseMeshCreator{}
218216
ctx := cfg.wsnet.ctx
219-
mesh, err := creator.create(
217+
mesh, err := newBaseMesher(
220218
withContext(ctx),
221219
withMeshNetMeshFn(cfg.wsnet.meshThreadInner),
222220
withMeshPeerStatReporter(func() {
@@ -266,7 +264,5 @@ func (c *noopMeshCreator) create(opts ...meshOption) (mesher, error) {
266264

267265
type noopMesh struct{}
268266

269-
func (m *noopMesh) start() {
270-
}
271-
func (m *noopMesh) stop() {
272-
}
267+
func (m *noopMesh) start() {}
268+
func (m *noopMesh) stop() {}

network/p2pNetwork.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ func (n *P2PNetwork) setup() error {
352352
n.meshUpdateRequests = make(chan meshRequest, 5)
353353
meshCreator := n.meshCreator
354354
if meshCreator == nil {
355-
meshCreator = &BaseMeshCreator{}
355+
meshCreator = &baseMeshCreator{}
356356
}
357357
var err error
358358
n.mesher, err = meshCreator.create(

network/wsNetwork.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ func (wn *WebsocketNetwork) setup() error {
599599
wn.meshUpdateRequests = make(chan meshRequest, 5)
600600
meshCreator := wn.meshCreator
601601
if meshCreator == nil {
602-
meshCreator = &BaseMeshCreator{}
602+
meshCreator = &baseMeshCreator{}
603603
}
604604
var err error
605605
wn.mesher, err = meshCreator.create(

node/node.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func MakeFull(log logging.Logger, rootDir string, cfg config.Local, phonebookAdd
212212
}
213213
recreateNetwork:
214214
if cfg.EnableP2PHybridMode {
215-
p2pNode, err = network.NewHybridP2PNetwork(node.log, node.config, rootDir, phonebookAddresses, genesisInfo, node, &network.HybridRelayMeshCreator{})
215+
p2pNode, err = network.NewHybridP2PNetwork(node.log, node.config, rootDir, phonebookAddresses, genesisInfo, node, nil)
216216
if err != nil {
217217
if _, ok := err.(config.P2PHybridConfigError); !ok {
218218
log.Errorf("could not create hybrid p2p node: %v", err)
@@ -232,14 +232,14 @@ recreateNetwork:
232232
goto recreateNetwork
233233
}
234234
} else if cfg.EnableP2P {
235-
p2pNode, err = network.NewP2PNetwork(node.log, node.config, rootDir, phonebookAddresses, genesisInfo, node, nil, &network.BaseMeshCreator{})
235+
p2pNode, err = network.NewP2PNetwork(node.log, node.config, rootDir, phonebookAddresses, genesisInfo, node, nil, nil)
236236
if err != nil {
237237
log.Errorf("could not create p2p node: %v", err)
238238
return nil, err
239239
}
240240
} else {
241241
var wsNode *network.WebsocketNetwork
242-
wsNode, err = network.NewWebsocketNetwork(node.log, node.config, phonebookAddresses, genesisInfo, node, nil, &network.BaseMeshCreator{})
242+
wsNode, err = network.NewWebsocketNetwork(node.log, node.config, phonebookAddresses, genesisInfo, node, nil, nil)
243243
if err != nil {
244244
log.Errorf("could not create websocket node: %v", err)
245245
return nil, err

0 commit comments

Comments
 (0)