From 86acc5d91496cde7cf2e55c83dc53a883ecaf226 Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Wed, 6 Dec 2017 13:56:28 +0100 Subject: [PATCH] p2p/enr: use SizeLimit const instead of hardcoded 300 bytes. --- p2p/enr/enr.go | 10 +++++++--- p2p/enr/enr_test.go | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/p2p/enr/enr.go b/p2p/enr/enr.go index 7d0a0a83d2..d2ee5b4bd2 100644 --- a/p2p/enr/enr.go +++ b/p2p/enr/enr.go @@ -33,6 +33,10 @@ import ( "github.com/ethereum/go-ethereum/rlp" ) +const ( + SizeLimit = 300 +) + var ( errNoID = errors.New("unknown or unspecified identity scheme") errInvalidSigsize = errors.New("invalid signature size") @@ -40,7 +44,7 @@ var ( errNotSorted = errors.New("record key/value pairs are not sorted by key") errDuplicateKey = errors.New("record contains duplicate key") errIncompletePair = errors.New("record contains incomplete k/v pair") - errTooBig = errors.New("record bigger than 300 bytes") + errTooBig = fmt.Errorf("record bigger than %d bytes", SizeLimit) ) // Key is implemented by known node record key types. @@ -201,7 +205,7 @@ func (r *Record) NodeAddr() ([]byte, error) { // Sign signs the record with the provided private key. // It updates record's identity scheme and public key. -// It returns an error if signed record is bigger than 300 bytes. +// It returns an error if signed record is bigger than SizeLimit bytes. func (r *Record) Sign(privkey *ecdsa.PrivateKey) error { pk := (*btcec.PublicKey)(&privkey.PublicKey) r.seq = r.seq + 1 @@ -239,7 +243,7 @@ func (r *Record) signAndEncode(privkey *ecdsa.PrivateKey) error { return err } - if len(r.raw) > 300 { + if len(r.raw) > SizeLimit { return errTooBig } diff --git a/p2p/enr/enr_test.go b/p2p/enr/enr_test.go index cdc77ea15f..b786ca9103 100644 --- a/p2p/enr/enr_test.go +++ b/p2p/enr/enr_test.go @@ -281,7 +281,7 @@ func TestPythonInterop(t *testing.T) { } } -// TestRecordTooBig tests that records bigger than 300 bytes cannot be signed. +// TestRecordTooBig tests that records bigger than SizeLimit bytes cannot be signed. func TestRecordTooBig(t *testing.T) { privkey, err := crypto.HexToECDSA(privkeyHex) if err != nil {