Commit 836c2ed 1 parent ba87d24 commit 836c2ed Copy full SHA for 836c2ed
File tree 3 files changed +42
-19
lines changed
3 files changed +42
-19
lines changed Original file line number Diff line number Diff line change 4
4
"errors"
5
5
"fmt"
6
6
"github.com/ethereum/go-ethereum/metrics"
7
+ "github.com/ethereum/go-ethereum/p2p/enode"
7
8
"math"
8
9
"math/rand"
9
10
"strings"
@@ -709,14 +710,21 @@ func (h *handler) highestPeerProgress() PeerProgress {
709
710
return max
710
711
}
711
712
713
+ // isUseless checks if the peer is banned from discovery and ban it if it should be
714
+ func isUseless (node * enode.Node , name string ) bool {
715
+ useless := discfilter .Banned (node .ID (), node .Record ())
716
+ lowerName := strings .ToLower (name )
717
+ if ! useless && ! strings .Contains (lowerName , "opera" ) && ! strings .Contains (lowerName , "sonic" ) {
718
+ useless = true
719
+ discfilter .Ban (node .ID ())
720
+ }
721
+ return useless
722
+ }
723
+
712
724
// handle is the callback invoked to manage the life cycle of a peer. When
713
725
// this function terminates, the peer is disconnected.
714
726
func (h * handler ) handle (p * peer ) error {
715
- useless := discfilter .Banned (p .Node ().ID (), p .Node ().Record ())
716
- if ! useless && ! strings .Contains (strings .ToLower (p .Name ()), "opera" ) {
717
- useless = true
718
- discfilter .Ban (p .ID ())
719
- }
727
+ useless := isUseless (p .Node (), p .Name ())
720
728
if ! p .Peer .Info ().Network .Trusted && useless && h .peers .UselessNum () >= h .maxPeers / 10 {
721
729
// don't allow more than 10% of useless peers
722
730
p .Log ().Trace ("Rejecting peer as useless" )
Original file line number Diff line number Diff line change
1
+ package gossip
2
+
3
+ import (
4
+ "github.com/ethereum/go-ethereum/p2p/discover/discfilter"
5
+ "github.com/ethereum/go-ethereum/p2p/enode"
6
+ "testing"
7
+ )
8
+
9
+ func TestIsUseless (t * testing.T ) {
10
+ validEnode := enode .MustParse ("enode://3f4306c065eaa5d8079e17feb56c03a97577e67af3c9c17496bb8916f102f1ff603e87d2a4ebfa0a2f70b780b85db212618857ea4e9627b24a9b0dd2faeb826e@127.0.0.1:5050" )
11
+ sonicName := "Sonic/v1.0.0-a-61af51c2-1715085138/linux-amd64/go1.21.7"
12
+ operaName := "go-opera/v1.1.2-rc.6-8e84c9dc-1688013329/linux-amd64/go1.19.11"
13
+ invalidName := "bot"
14
+
15
+ discfilter .Enable ()
16
+ if isUseless (validEnode , sonicName ) {
17
+ t .Errorf ("sonic peer reported as useless" )
18
+ }
19
+ if isUseless (validEnode , operaName ) {
20
+ t .Errorf ("opera peer reported as useless" )
21
+ }
22
+ if ! isUseless (validEnode , invalidName ) {
23
+ t .Errorf ("invalid peer not reported as useless" )
24
+ }
25
+ if ! isUseless (validEnode , operaName ) {
26
+ t .Errorf ("peer not banned after marking as useless" )
27
+ }
28
+ }
Original file line number Diff line number Diff line change @@ -2,25 +2,16 @@ package version
2
2
3
3
import (
4
4
"fmt"
5
- "math/big"
6
-
7
5
"github.com/ethereum/go-ethereum/params"
8
6
)
9
7
10
8
func init () {
11
9
params .VersionMajor = 1 // Major version component of the current release
12
- params .VersionMinor = 0 // Minor version component of the current release
10
+ params .VersionMinor = 2 // Minor version component of the current release
13
11
params .VersionPatch = 0 // Patch version component of the current release
14
12
params .VersionMeta = "a" // Version metadata to append to the version string
15
13
}
16
14
17
- func BigToString (b * big.Int ) string {
18
- if len (b .Bytes ()) > 8 {
19
- return "_malformed_version_"
20
- }
21
- return U64ToString (b .Uint64 ())
22
- }
23
-
24
15
func AsString () string {
25
16
return ToString (uint16 (params .VersionMajor ), uint16 (params .VersionMinor ), uint16 (params .VersionPatch ))
26
17
}
@@ -29,10 +20,6 @@ func AsU64() uint64 {
29
20
return ToU64 (uint16 (params .VersionMajor ), uint16 (params .VersionMinor ), uint16 (params .VersionPatch ))
30
21
}
31
22
32
- func AsBigInt () * big.Int {
33
- return new (big.Int ).SetUint64 (AsU64 ())
34
- }
35
-
36
23
func ToU64 (vMajor , vMinor , vPatch uint16 ) uint64 {
37
24
return uint64 (vMajor )* 1e12 + uint64 (vMinor )* 1e6 + uint64 (vPatch )
38
25
}
You can’t perform that action at this time.
0 commit comments