(squash) more fixes from review

This commit is contained in:
Ethan Buchman 2018-10-05 20:07:24 -04:00
parent bfd6146c28
commit 281e8fa0f4
4 changed files with 8 additions and 15 deletions

View File

@ -20,7 +20,7 @@ func MaxNodeInfoSize() int {
type NodeInfo interface {
ID() ID
Validate() error
ValidateBasic() error
CompatibleWith(other NodeInfo) error
NetAddress() *NetAddress
String() string
@ -72,7 +72,7 @@ func (info DefaultNodeInfo) ID() ID {
return info.ID_
}
// Validate checks the self-reported DefaultNodeInfo is safe.
// ValidateBasic checks the self-reported DefaultNodeInfo is safe.
// It returns an error if there
// are too many Channels, if there are any duplicate Channels,
// if the ListenAddr is malformed, or if the ListenAddr is a host name
@ -85,7 +85,7 @@ func (info DefaultNodeInfo) ID() ID {
// International clients could then use punycode (or we could use
// url-encoding), and we just need to be careful with how we handle that in our
// clients. (e.g. off by default).
func (info DefaultNodeInfo) Validate() error {
func (info DefaultNodeInfo) ValidateBasic() error {
if len(info.Channels) > maxNumChannels {
return fmt.Errorf("info.Channels is too long (%v). Max is %v", len(info.Channels), maxNumChannels)
}

View File

@ -122,9 +122,9 @@ func TestSwitches(t *testing.T) {
ch1Msg := []byte("channel foo")
ch2Msg := []byte("channel bar")
bch := s1.Broadcast(byte(0x00), ch0Msg)
bch = s1.Broadcast(byte(0x01), ch1Msg)
bch = s1.Broadcast(byte(0x02), ch2Msg)
s1.Broadcast(byte(0x00), ch0Msg)
s1.Broadcast(byte(0x01), ch1Msg)
s1.Broadcast(byte(0x02), ch2Msg)
assertMsgReceivedWithTimeout(t, ch0Msg, byte(0x00), s2.Reactor("foo").(*TestReactor), 10*time.Millisecond, 5*time.Second)
assertMsgReceivedWithTimeout(t, ch1Msg, byte(0x01), s2.Reactor("foo").(*TestReactor), 10*time.Millisecond, 5*time.Second)

View File

@ -187,16 +187,9 @@ func MakeSwitch(
) *Switch {
ni, nodeKey := testRandNodeInfo(i, network, version)
//addr := ni.NetAddress()
addr, err := NewNetAddressStringWithOptionalID(
IDAddressString(nodeKey.ID(), ni.(DefaultNodeInfo).ListenAddr),
)
if err != nil {
panic(err)
}
t := NewMultiplexTransport(ni, nodeKey)
addr := ni.NetAddress()
if err := t.Listen(*addr); err != nil {
panic(err)
}

View File

@ -351,7 +351,7 @@ func (mt *MultiplexTransport) upgrade(
}
}
if err := nodeInfo.Validate(); err != nil {
if err := nodeInfo.ValidateBasic(); err != nil {
return nil, nil, ErrRejected{
conn: c,
err: err,