Skip to content

Commit 9284b43

Browse files
committed
refactor: add verbose flag to transport controller
Signed-off-by: Christian Stewart <christian@aperture.us>
1 parent 346af11 commit 9284b43

File tree

20 files changed

+310
-16
lines changed

20 files changed

+310
-16
lines changed

transport/controller/controller.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ type Controller struct {
7474
// lookupPeerID is the peer id to lookup on the bus
7575
// may be empty
7676
lookupPeerID peer.ID
77+
// verbose enables verbose logs
78+
verbose bool
7779

7880
// linkDialers tracks ongoing dial attempts
7981
// when a link is closed (removed from links) the associated dialer is restarted (if any).
@@ -102,6 +104,7 @@ func NewController(
102104
bus bus.Bus,
103105
info *controller.Info,
104106
peerID peer.ID,
107+
verbose bool,
105108
ctor Constructor,
106109
) *Controller {
107110
c := &Controller{
@@ -110,6 +113,7 @@ func NewController(
110113
ctor: ctor,
111114
info: info,
112115
lookupPeerID: peerID,
116+
verbose: verbose,
113117

114118
links: make(map[uint64]*establishedLink),
115119
linksByPeerID: make(map[peer.ID][]*establishedLink),
@@ -146,9 +150,6 @@ func (c *Controller) GetPeerLinks(peerID peer.ID) []link.Link {
146150
// Returning an error triggers a retry with backoff.
147151
func (c *Controller) Execute(ctx context.Context) error {
148152
// Acquire a handle to the node.
149-
c.le.
150-
WithField("peer-id", c.lookupPeerID.String()).
151-
Debug("waiting for peer private key")
152153
localPeer, _, localPeerRef, err := peer.GetPeerWithID(ctx, c.bus, c.lookupPeerID, false, nil)
153154
if err != nil {
154155
return err
@@ -182,7 +183,9 @@ func (c *Controller) Execute(ctx context.Context) error {
182183
// store the transport
183184
handler.tpt.SetResult(tpt, nil)
184185

185-
c.le.Debug("executing transport")
186+
if c.verbose {
187+
c.le.Debug("executing transport")
188+
}
186189
execCtx, execCtxCancel := context.WithCancel(ctx)
187190
defer execCtxCancel()
188191

@@ -302,7 +305,9 @@ func (c *Controller) HandleIncomingStream(
302305

303306
// bus is the controller bus
304307
le := c.loggerForLink(lnk).WithField("protocol-id", pid)
305-
le.Debug("accepted stream")
308+
if c.verbose {
309+
le.Debug("accepted stream")
310+
}
306311

307312
dir := link.NewHandleMountedStream(pid, lnk.GetLocalPeer(), mstrm.GetPeerID())
308313

transport/controller/mounted-link.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,17 @@ func (l *mountedLink) OpenMountedStream(
7878
}
7979

8080
_ = strm.SetDeadline(time.Time{})
81-
l.c.le.
82-
WithFields(logrus.Fields{
83-
"link-id": l.link.GetUUID(),
84-
"protocol-id": protocolID,
85-
"src-peer": l.link.GetLocalPeer().String(),
86-
"dst-peer": l.link.GetRemotePeer().String(),
87-
}).
88-
Debug("opened stream with peer")
81+
if l.c.verbose {
82+
l.c.le.
83+
WithFields(logrus.Fields{
84+
"link-id": l.link.GetUUID(),
85+
"protocol-id": protocolID,
86+
"src-peer": l.link.GetLocalPeer().String(),
87+
"dst-peer": l.link.GetRemotePeer().String(),
88+
}).
89+
Debug("opened stream with peer")
90+
}
91+
8992
return newMountedStream(strm, opts, protocolID, l), nil
9093
}
9194

transport/inproc/factory.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func (t *Factory) Construct(
5959
t.bus,
6060
controller.NewInfo(ControllerID, Version, "in-proc transport"),
6161
peerIDConstraint,
62+
cc.GetVerbose(),
6263
func(
6364
ctx context.Context,
6465
le *logrus.Entry,

transport/inproc/inproc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ func BuildInprocController(
100100
b,
101101
controller.NewInfo(ControllerID, Version, "in-proc transport"),
102102
peerIDConstraint,
103+
conf.GetVerbose(),
103104
func(
104105
ctx context.Context,
105106
le *logrus.Entry,

transport/inproc/inproc.pb.go

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

transport/inproc/inproc.pb.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ export interface Config {
3434
* @generated from field: map<string, dialer.DialerOpts> dialers = 3;
3535
*/
3636
dialers?: { [key: string]: DialerOpts }
37+
/**
38+
* Verbose enables verbose logging.
39+
*
40+
* @generated from field: bool verbose = 4;
41+
*/
42+
verbose?: boolean
3743
}
3844

3945
// Config contains the message type declaration for Config.
@@ -49,6 +55,7 @@ export const Config: MessageType<Config> = createMessageType({
4955
K: ScalarType.STRING,
5056
V: { kind: 'message', T: () => DialerOpts },
5157
},
58+
{ no: 4, name: 'verbose', kind: 'scalar', T: ScalarType.BOOL },
5259
] as readonly PartialFieldInfo[],
5360
packedByDefault: true,
5461
})

transport/inproc/inproc.proto

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ message Config {
1010
// If unset, attaches to any running peer with a private key.
1111
string transport_peer_id = 1;
1212
// PacketOpts are options to set on the packet connection.
13-
pconn.Opts packet_opts = 2;
13+
.pconn.Opts packet_opts = 2;
1414
// Dialers maps peer IDs to dialers.
1515
map<string, dialer.DialerOpts> dialers = 3;
16+
// Verbose enables verbose logging.
17+
bool verbose = 4;
1618
}
1719

transport/udp/factory.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func (t *Factory) Construct(
5959
t.bus,
6060
controller.NewInfo(ControllerID, Version, "udp transport"),
6161
peerIDConstraint,
62+
cc.GetVerbose(),
6263
func(
6364
ctx context.Context,
6465
le *logrus.Entry,

0 commit comments

Comments
 (0)