File tree Expand file tree Collapse file tree 3 files changed +2
-47
lines changed Expand file tree Collapse file tree 3 files changed +2
-47
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,6 @@ import { defaults } from "../../src/defaults";
55import { Peer } from "../../src/peer" ;
66import { setUp , tearDown } from "../__support__/setup" ;
77
8- const CORE_ENV = process . env . CORE_ENV ;
98let guard ;
109let peerMock ;
1110
@@ -35,18 +34,14 @@ beforeEach(async () => {
3534describe ( "Guard" , ( ) => {
3635 describe ( "isSuspended" , ( ) => {
3736 it ( "should return true" , async ( ) => {
38- process . env . CORE_ENV = "false" ;
3937 await guard . monitor . acceptNewPeer ( peerMock ) ;
40- process . env . CORE_ENV = CORE_ENV ;
4138
4239 expect ( guard . isSuspended ( peerMock ) ) . toBe ( true ) ;
4340 } ) ;
4441
4542 it ( "should return false because passed" , async ( ) => {
46- process . env . CORE_ENV = "false" ;
4743 await guard . monitor . acceptNewPeer ( peerMock ) ;
4844 guard . suspensions [ peerMock . ip ] . until = dayjs ( ) . subtract ( 1 , "minute" ) ;
49- process . env . CORE_ENV = CORE_ENV ;
5045
5146 expect ( guard . isSuspended ( peerMock ) ) . toBe ( false ) ;
5247 } ) ;
Original file line number Diff line number Diff line change @@ -71,13 +71,9 @@ describe("Monitor", () => {
7171 peerMock . headers ,
7272 ] ) ;
7373
74- process . env . CORE_ENV = "false" ;
75-
7674 await monitor . acceptNewPeer ( peerMock ) ;
7775
7876 expect ( monitor . peers [ peerMock . ip ] ) . toBeObject ( ) ;
79-
80- process . env . CORE_ENV = "test" ;
8177 } ) ;
8278 } ) ;
8379
Original file line number Diff line number Diff line change @@ -140,12 +140,7 @@ export class Monitor implements P2P.IMonitor {
140140 return ;
141141 }
142142
143- if (
144- ! isValidPeer ( peer ) ||
145- this . guard . isSuspended ( peer ) ||
146- this . pendingPeers [ peer . ip ] ||
147- process . env . CORE_ENV === "test"
148- ) {
143+ if ( ! isValidPeer ( peer ) || this . guard . isSuspended ( peer ) || this . pendingPeers [ peer . ip ] ) {
149144 return ;
150145 }
151146
@@ -390,9 +385,7 @@ export class Monitor implements P2P.IMonitor {
390385 const hisPeers = await peer . getPeers ( ) ;
391386
392387 for ( const p of hisPeers ) {
393- if ( isValidPeer ( p ) && ! this . getPeer ( p . ip ) ) {
394- this . addPeer ( p ) ;
395- }
388+ this . acceptNewPeer ( p ) ;
396389 }
397390 } catch ( error ) {
398391 // Just try with the next peer from shuffledPeers.
@@ -769,35 +762,6 @@ export class Monitor implements P2P.IMonitor {
769762 }
770763 }
771764
772- /**
773- * Add a new peer after it passes a few checks.
774- * @param {Peer } peer
775- * @return {void }
776- */
777- private addPeer ( peer ) {
778- if ( this . guard . isBlacklisted ( peer ) ) {
779- return ;
780- }
781-
782- if ( ! this . guard . isValidVersion ( peer ) ) {
783- return ;
784- }
785-
786- if ( ! this . guard . isValidNetwork ( peer ) ) {
787- return ;
788- }
789-
790- if ( ! this . guard . isValidMilestoneHash ( peer ) ) {
791- return ;
792- }
793-
794- if ( ! this . guard . isValidPort ( peer ) ) {
795- return ;
796- }
797-
798- this . peers [ peer . ip ] = new Peer ( peer . ip , peer . port ) ;
799- }
800-
801765 /**
802766 * Schedule the next update network status.
803767 * @param {Number } nextUpdateInSeconds
You can’t perform that action at this time.
0 commit comments