forked from sei-protocol/sei-tendermint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pex.go
33 lines (29 loc) · 799 Bytes
/
pex.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package p2p
import (
"fmt"
"github.com/gogo/protobuf/proto"
)
// Wrap implements the p2p Wrapper interface and wraps a PEX message.
func (m *PexMessage) Wrap(pb proto.Message) error {
switch msg := pb.(type) {
case *PexRequest:
m.Sum = &PexMessage_PexRequest{PexRequest: msg}
case *PexResponse:
m.Sum = &PexMessage_PexResponse{PexResponse: msg}
default:
return fmt.Errorf("unknown pex message: %T", msg)
}
return nil
}
// Unwrap implements the p2p Wrapper interface and unwraps a wrapped PEX
// message.
func (m *PexMessage) Unwrap() (proto.Message, error) {
switch msg := m.Sum.(type) {
case *PexMessage_PexRequest:
return msg.PexRequest, nil
case *PexMessage_PexResponse:
return msg.PexResponse, nil
default:
return nil, fmt.Errorf("unknown pex message: %T", msg)
}
}