@@ -55,6 +55,7 @@ const {
55
55
_createSocketHandle,
56
56
newHandle,
57
57
} = require ( 'internal/dgram' ) ;
58
+ const { isIP } = require ( 'internal/net' ) ;
58
59
const {
59
60
isInt32,
60
61
validateAbortSignal,
@@ -104,6 +105,8 @@ function Socket(type, listener) {
104
105
let lookup ;
105
106
let recvBufferSize ;
106
107
let sendBufferSize ;
108
+ let receiveBlockList ;
109
+ let sendBlockList ;
107
110
108
111
let options ;
109
112
if ( type !== null && typeof type === 'object' ) {
@@ -112,6 +115,14 @@ function Socket(type, listener) {
112
115
lookup = options . lookup ;
113
116
recvBufferSize = options . recvBufferSize ;
114
117
sendBufferSize = options . sendBufferSize ;
118
+ // TODO: validate the params
119
+ // https://github.com/nodejs/node/pull/56078
120
+ if ( options . receiveBlockList ) {
121
+ receiveBlockList = options . receiveBlockList ;
122
+ }
123
+ if ( options . sendBlockList ) {
124
+ sendBlockList = options . sendBlockList ;
125
+ }
115
126
}
116
127
117
128
const handle = newHandle ( type , lookup ) ;
@@ -134,6 +145,8 @@ function Socket(type, listener) {
134
145
ipv6Only : options ?. ipv6Only ,
135
146
recvBufferSize,
136
147
sendBufferSize,
148
+ receiveBlockList,
149
+ sendBlockList,
137
150
} ;
138
151
139
152
if ( options ?. signal !== undefined ) {
@@ -434,9 +447,14 @@ function doConnect(ex, self, ip, address, port, callback) {
434
447
return ;
435
448
436
449
if ( ! ex ) {
437
- const err = state . handle . connect ( ip , port ) ;
438
- if ( err ) {
439
- ex = new ExceptionWithHostPort ( err , 'connect' , address , port ) ;
450
+ if ( state . sendBlockList ?. check ( ip , `ipv${ isIP ( ip ) } ` ) ) {
451
+ // TODO
452
+ ex = new Error ( ) ;
453
+ } else {
454
+ const err = state . handle . connect ( ip , port ) ;
455
+ if ( err ) {
456
+ ex = new ExceptionWithHostPort ( err , 'connect' , address , port ) ;
457
+ }
440
458
}
441
459
}
442
460
@@ -696,6 +714,14 @@ function doSend(ex, self, ip, list, address, port, callback) {
696
714
return ;
697
715
}
698
716
717
+ if ( port && state . sendBlockList ?. check ( ip , `ipv${ isIP ( ip ) } ` ) ) {
718
+ if ( callback ) {
719
+ // TODO
720
+ process . nextTick ( callback , new Error ( ) ) ;
721
+ }
722
+ return ;
723
+ }
724
+
699
725
const req = new SendWrap ( ) ;
700
726
req . list = list ; // Keep reference alive.
701
727
req . address = address ;
@@ -944,6 +970,10 @@ function onMessage(nread, handle, buf, rinfo) {
944
970
if ( nread < 0 ) {
945
971
return self . emit ( 'error' , new ErrnoException ( nread , 'recvmsg' ) ) ;
946
972
}
973
+ if ( self [ kStateSymbol ] ?. receiveBlockList ?. check ( rinfo . address ,
974
+ rinfo . family . toLocaleLowerCase ( ) ) ) {
975
+ return ;
976
+ }
947
977
rinfo . size = buf . length ; // compatibility
948
978
self . emit ( 'message' , buf , rinfo ) ;
949
979
}
0 commit comments