@@ -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 ) {
@@ -432,7 +445,10 @@ function doConnect(ex, self, ip, address, port, callback) {
432
445
const state = self [ kStateSymbol ] ;
433
446
if ( ! state . handle )
434
447
return ;
435
-
448
+ if ( ! ex && state . sendBlockList ?. check ( ip , `ipv${ isIP ( ip ) } ` ) ) {
449
+ // TODO
450
+ ex = new ERR_SOCKET_DGRAM_IS_CONNECTED ( ) ;
451
+ }
436
452
if ( ! ex ) {
437
453
const err = state . handle . connect ( ip , port ) ;
438
454
if ( err ) {
@@ -696,6 +712,14 @@ function doSend(ex, self, ip, list, address, port, callback) {
696
712
return ;
697
713
}
698
714
715
+ if ( port && state . sendBlockList ?. check ( ip , `ipv${ isIP ( ip ) } ` ) ) {
716
+ if ( callback ) {
717
+ // TODO
718
+ process . nextTick ( callback , new ERR_SOCKET_DGRAM_IS_CONNECTED ( ) ) ;
719
+ }
720
+ return ;
721
+ }
722
+
699
723
const req = new SendWrap ( ) ;
700
724
req . list = list ; // Keep reference alive.
701
725
req . address = address ;
@@ -944,6 +968,10 @@ function onMessage(nread, handle, buf, rinfo) {
944
968
if ( nread < 0 ) {
945
969
return self . emit ( 'error' , new ErrnoException ( nread , 'recvmsg' ) ) ;
946
970
}
971
+ if ( self [ kStateSymbol ] ?. receiveBlockList ?. check ( rinfo . address ,
972
+ rinfo . family ?. toLocaleLowerCase ( ) ) ) {
973
+ return ;
974
+ }
947
975
rinfo . size = buf . length ; // compatibility
948
976
self . emit ( 'message' , buf , rinfo ) ;
949
977
}
0 commit comments