Skip to content

Commit 768d2a0

Browse files
committed
p2p: fix codeclimate warnings
License: MIT Signed-off-by: Łukasz Magiera <[email protected]>
1 parent 08ae673 commit 768d2a0

File tree

5 files changed

+22
-21
lines changed

5 files changed

+22
-21
lines changed

core/commands/p2p.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,9 @@ var p2pStreamLsCmd = &cmds.Command{
322322

323323
output := &P2PStreamsOutput{}
324324

325-
for _, s := range n.P2P.Streams.Streams {
325+
for id, s := range n.P2P.Streams.Streams {
326326
output.Streams = append(output.Streams, P2PStreamInfoOutput{
327-
HandlerID: strconv.FormatUint(s.Id, 10),
327+
HandlerID: strconv.FormatUint(id, 10),
328328

329329
Protocol: s.Protocol,
330330

@@ -366,7 +366,7 @@ var p2pStreamCloseCmd = &cmds.Command{
366366
Tagline: "Close active p2p stream.",
367367
},
368368
Arguments: []cmdkit.Argument{
369-
cmdkit.StringArg("Id", false, false, "Stream Id"),
369+
cmdkit.StringArg("id", false, false, "Stream identifier"),
370370
},
371371
Options: []cmdkit.Option{
372372
cmdkit.BoolOption("all", "a", "Close all streams."),
@@ -385,7 +385,7 @@ var p2pStreamCloseCmd = &cmds.Command{
385385

386386
if !closeAll {
387387
if len(req.Arguments()) == 0 {
388-
res.SetError(errors.New("no Id specified"), cmdkit.ErrNormal)
388+
res.SetError(errors.New("no id specified"), cmdkit.ErrNormal)
389389
return
390390
}
391391

@@ -396,8 +396,8 @@ var p2pStreamCloseCmd = &cmds.Command{
396396
}
397397
}
398398

399-
for _, stream := range n.P2P.Streams.Streams {
400-
if !closeAll && handlerID != stream.Id {
399+
for id, stream := range n.P2P.Streams.Streams {
400+
if !closeAll && handlerID != id {
401401
continue
402402
}
403403
stream.Reset()

p2p/listener.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"sync"
66
)
77

8+
// Listener listens for connections and proxies them to a target
89
type Listener interface {
910
Protocol() string
1011
ListenAddress() string
@@ -26,7 +27,7 @@ type ListenerRegistry struct {
2627
lk *sync.Mutex
2728
}
2829

29-
func (r *ListenerRegistry) Lock(l Listener) error {
30+
func (r *ListenerRegistry) lock(l Listener) error {
3031
r.lk.Lock()
3132

3233
if _, ok := r.Listeners[getListenerKey(l)]; ok {
@@ -36,7 +37,7 @@ func (r *ListenerRegistry) Lock(l Listener) error {
3637
return nil
3738
}
3839

39-
func (r *ListenerRegistry) Unlock() {
40+
func (r *ListenerRegistry) unlock() {
4041
r.lk.Unlock()
4142
}
4243

p2p/local.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ func (p2p *P2P) ForwardLocal(ctx context.Context, peer peer.ID, proto string, bi
3939
peer: peer,
4040
}
4141

42-
if err := p2p.Listeners.Lock(listener); err != nil {
42+
if err := p2p.Listeners.lock(listener); err != nil {
4343
return nil, err
4444
}
4545

4646
maListener, err := manet.Listen(bindAddr)
4747
if err != nil {
48-
p2p.Listeners.Unlock()
48+
p2p.Listeners.unlock()
4949
return nil, err
5050
}
5151

p2p/remote.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func (p2p *P2P) ForwardRemote(ctx context.Context, proto string, addr ma.Multiad
2929
addr: addr,
3030
}
3131

32-
if err := p2p.Listeners.Lock(listener); err != nil {
32+
if err := p2p.Listeners.lock(listener); err != nil {
3333
return nil, err
3434
}
3535

p2p/stream.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
// Stream holds information on active incoming and outgoing p2p streams.
1313
type Stream struct {
14-
Id uint64
14+
id uint64
1515

1616
Protocol string
1717

@@ -28,15 +28,15 @@ type Stream struct {
2828
func (s *Stream) Close() error {
2929
s.Local.Close()
3030
s.Remote.Close()
31-
s.Registry.Deregister(s.Id)
31+
s.Registry.Deregister(s.id)
3232
return nil
3333
}
3434

35-
// Rest closes stream endpoints and deregisters it
35+
// Reset closes stream endpoints and deregisters it
3636
func (s *Stream) Reset() error {
3737
s.Local.Close()
3838
s.Remote.Reset()
39-
s.Registry.Deregister(s.Id)
39+
s.Registry.Deregister(s.id)
4040
return nil
4141
}
4242

@@ -61,23 +61,23 @@ type StreamRegistry struct {
6161
Streams map[uint64]*Stream
6262
lk *sync.Mutex
6363

64-
nextId uint64
64+
nextID uint64
6565
}
6666

6767
// Register registers a stream to the registry
6868
func (r *StreamRegistry) Register(streamInfo *Stream) {
6969
r.lk.Lock()
7070
defer r.lk.Unlock()
7171

72-
streamInfo.Id = r.nextId
73-
r.Streams[r.nextId] = streamInfo
74-
r.nextId++
72+
streamInfo.id = r.nextID
73+
r.Streams[r.nextID] = streamInfo
74+
r.nextID++
7575
}
7676

7777
// Deregister deregisters stream from the registry
78-
func (r *StreamRegistry) Deregister(streamId uint64) {
78+
func (r *StreamRegistry) Deregister(streamID uint64) {
7979
r.lk.Lock()
8080
defer r.lk.Unlock()
8181

82-
delete(r.Streams, streamId)
82+
delete(r.Streams, streamID)
8383
}

0 commit comments

Comments
 (0)