mirror of
https://github.com/tendermint/tendermint.git
synced 2025-12-23 06:15:19 +00:00
* p2p: add a per-message type send and receive metric (#9622) * p2p: ressurrect the p2p envelope and use to calculate message metric Add new SendEnvelope, TrySendEnvelope, BroadcastEnvelope, and ReceiveEnvelope methods in the p2p package to work with the new envelope type. Care was taken to ensure this was performed in a non-breaking manner. Co-authored-by: William Banfield <4561443+williambanfield@users.noreply.github.com> Co-authored-by: William Banfield <wbanfield@gmail.com>
55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
package statesync
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/gogo/protobuf/proto"
|
|
|
|
ssproto "github.com/tendermint/tendermint/proto/tendermint/statesync"
|
|
)
|
|
|
|
const (
|
|
// snapshotMsgSize is the maximum size of a snapshotResponseMessage
|
|
snapshotMsgSize = int(4e6)
|
|
// chunkMsgSize is the maximum size of a chunkResponseMessage
|
|
chunkMsgSize = int(16e6)
|
|
)
|
|
|
|
// validateMsg validates a message.
|
|
func validateMsg(pb proto.Message) error {
|
|
if pb == nil {
|
|
return errors.New("message cannot be nil")
|
|
}
|
|
switch msg := pb.(type) {
|
|
case *ssproto.ChunkRequest:
|
|
if msg.Height == 0 {
|
|
return errors.New("height cannot be 0")
|
|
}
|
|
case *ssproto.ChunkResponse:
|
|
if msg.Height == 0 {
|
|
return errors.New("height cannot be 0")
|
|
}
|
|
if msg.Missing && len(msg.Chunk) > 0 {
|
|
return errors.New("missing chunk cannot have contents")
|
|
}
|
|
if !msg.Missing && msg.Chunk == nil {
|
|
return errors.New("chunk cannot be nil")
|
|
}
|
|
case *ssproto.SnapshotsRequest:
|
|
case *ssproto.SnapshotsResponse:
|
|
if msg.Height == 0 {
|
|
return errors.New("height cannot be 0")
|
|
}
|
|
if len(msg.Hash) == 0 {
|
|
return errors.New("snapshot has no hash")
|
|
}
|
|
if msg.Chunks == 0 {
|
|
return errors.New("snapshot has no chunks")
|
|
}
|
|
default:
|
|
return fmt.Errorf("unknown message type %T", msg)
|
|
}
|
|
return nil
|
|
}
|