Skip to content

Commit

Permalink
refactor: Pass context todo
Browse files Browse the repository at this point in the history
  • Loading branch information
boecklim committed Dec 13, 2024
1 parent 8b47b98 commit 8c3944c
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func (p *Peer) connectAndStartReadWriteHandlers() error {
if err := wire.WriteMessage(p.readConn, msg, wire.ProtocolVersion, p.network); err != nil {
return fmt.Errorf("failed to write message: %v", err)
}
p.logger.Log(p.ctx, LevelTrace, sentMsg, slog.String(commandKey, strings.ToUpper(msg.Command())))
p.logger.Log(context.TODO(), LevelTrace, sentMsg, slog.String(commandKey, strings.ToUpper(msg.Command())))

startWaitTime := time.Now()
for {
Expand Down Expand Up @@ -651,7 +651,7 @@ func (p *Peer) sendInvBatch(batch []*chainhash.Hash) {
for _, hash := range batch {
iv := wire.NewInvVect(wire.InvTypeTx, hash)
_ = invMsg.AddInvVect(iv)
p.logger.Log(p.ctx, LevelTrace, "Sent INV", slog.String(hashKey, hash.String()), slog.String(typeKey, wire.InvTypeTx.String()))
p.logger.Log(context.TODO(), LevelTrace, "Sent INV", slog.String(hashKey, hash.String()), slog.String(typeKey, wire.InvTypeTx.String()))
}

p.writeChan <- invMsg
Expand All @@ -663,13 +663,13 @@ func (p *Peer) sendDataBatch(batch []*chainhash.Hash) {
for _, hash := range batch {
iv := wire.NewInvVect(wire.InvTypeTx, hash)
_ = dataMsg.AddInvVect(iv)
p.logger.Log(p.ctx, LevelTrace, "Sent GETDATA", slog.String(hashKey, hash.String()), slog.String(typeKey, wire.InvTypeTx.String()))
p.logger.Log(context.TODO(), LevelTrace, "Sent GETDATA", slog.String(hashKey, hash.String()), slog.String(typeKey, wire.InvTypeTx.String()))
}

if err := p.WriteMsg(dataMsg); err != nil {
p.logger.Error("failed to send tx data message", slog.String(errKey, err.Error()))
} else {
p.logger.Log(p.ctx, LevelTrace, "Sent GETDATA", slog.Int("items", len(batch)))
p.logger.Log(context.TODO(), LevelTrace, "Sent GETDATA", slog.Int("items", len(batch)))
}
}

Expand Down Expand Up @@ -746,15 +746,15 @@ func (p *Peer) startWriteChannelHandler(ctx context.Context, instance int) {

switch m := message.(type) {
case *wire.MsgTx:
p.logger.Log(p.ctx, LevelTrace, sentMsg, slog.String(commandKey, strings.ToUpper(message.Command())), slog.String(hashKey, m.TxHash().String()), slog.String(typeKey, "tx"))
p.logger.Log(context.TODO(), LevelTrace, sentMsg, slog.String(commandKey, strings.ToUpper(message.Command())), slog.String(hashKey, m.TxHash().String()), slog.String(typeKey, "tx"))
case *wire.MsgBlock:
p.logger.Log(p.ctx, LevelTrace, sentMsg, slog.String(commandKey, strings.ToUpper(message.Command())), slog.String(hashKey, m.BlockHash().String()), slog.String(typeKey, "block"))
p.logger.Log(context.TODO(), LevelTrace, sentMsg, slog.String(commandKey, strings.ToUpper(message.Command())), slog.String(hashKey, m.BlockHash().String()), slog.String(typeKey, "block"))
case *wire.MsgGetData:
p.logger.Log(p.ctx, LevelTrace, sentMsg, slog.String(commandKey, strings.ToUpper(message.Command())), slog.String(hashKey, m.InvList[0].Hash.String()), slog.String(typeKey, "getdata"))
p.logger.Log(context.TODO(), LevelTrace, sentMsg, slog.String(commandKey, strings.ToUpper(message.Command())), slog.String(hashKey, m.InvList[0].Hash.String()), slog.String(typeKey, "getdata"))
case *wire.MsgInv:
p.logger.Log(p.ctx, LevelTrace, sentMsg, slog.String(commandKey, strings.ToUpper(message.Command())), slog.String(hashKey, m.InvList[0].Hash.String()), slog.String(typeKey, "inv"))
p.logger.Log(context.TODO(), LevelTrace, sentMsg, slog.String(commandKey, strings.ToUpper(message.Command())), slog.String(hashKey, m.InvList[0].Hash.String()), slog.String(typeKey, "inv"))
default:
p.logger.Log(p.ctx, LevelTrace, sentMsg, slog.String(commandKey, strings.ToUpper(message.Command())), slog.String(typeKey, "unknown"))
p.logger.Log(context.TODO(), LevelTrace, sentMsg, slog.String(commandKey, strings.ToUpper(message.Command())), slog.String(typeKey, "unknown"))
}
}(msg)
}
Expand Down

0 comments on commit 8c3944c

Please sign in to comment.