Skip to content

Commit

Permalink
Merge pull request #36 from arkadiuszos4chain/feat-buff-size
Browse files Browse the repository at this point in the history
feat: add read buffer size configuration
  • Loading branch information
boecklim authored Dec 13, 2024
2 parents 61a1165 + 7fa6d92 commit 92a304b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ type Peer struct {
writerWg *sync.WaitGroup
reconnectingWg *sync.WaitGroup
healthMonitorWg *sync.WaitGroup

buffSize int
}

// NewPeer returns a new bitcoin peer for the provided address and configuration.
Expand Down Expand Up @@ -121,6 +123,7 @@ func NewPeer(logger *slog.Logger, address string, peerHandler PeerHandlerI, netw
readerWg: &sync.WaitGroup{},
reconnectingWg: &sync.WaitGroup{},
healthMonitorWg: &sync.WaitGroup{},
buffSize: 4096,
}

var err error
Expand Down Expand Up @@ -405,7 +408,7 @@ func (p *Peer) startReadHandler(ctx context.Context) {
return
}

reader := bufio.NewReader(&io.LimitedReader{R: readConn, N: p.maximumMessageSize})
reader := bufio.NewReaderSize(&io.LimitedReader{R: readConn, N: p.maximumMessageSize}, p.buffSize)
for {
select {
case <-ctx.Done():
Expand Down
7 changes: 7 additions & 0 deletions peer_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,10 @@ func WithPingInterval(pingInterval time.Duration, connectionHealthThreshold time
return nil
}
}

func WithReadBufferSize(size int) PeerOptions {
return func(p *Peer) error {
p.buffSize = size
return nil
}
}

0 comments on commit 92a304b

Please sign in to comment.