@@ -63,16 +63,12 @@ export class EventMessageHandler implements IMessageHandler {
6363 protected canAcceptEvent ( event : Event ) : string | undefined {
6464 const now = Math . floor ( Date . now ( ) / 1000 )
6565 const limits = this . settings ( ) . limits . event
66- if ( limits . createdAt . maxPositiveDelta > 0 ) {
67- if ( event . created_at > now + limits . createdAt . maxPositiveDelta ) {
68- return `rejected: created_at is more than ${ limits . createdAt . maxPositiveDelta } seconds in the future`
69- }
66+ if ( limits . createdAt . maxPositiveDelta > 0 && event . created_at > now + limits . createdAt . maxPositiveDelta ) {
67+ return `rejected: created_at is more than ${ limits . createdAt . maxPositiveDelta } seconds in the future`
7068 }
7169
72- if ( limits . createdAt . maxNegativeDelta > 0 ) {
73- if ( event . created_at < now - limits . createdAt . maxNegativeDelta ) {
74- return `rejected: created_at is more than ${ limits . createdAt . maxNegativeDelta } seconds in the past`
75- }
70+ if ( limits . createdAt . maxNegativeDelta > 0 && event . created_at < now - limits . createdAt . maxNegativeDelta ) {
71+ return `rejected: created_at is more than ${ limits . createdAt . maxNegativeDelta } seconds in the past`
7672 }
7773
7874 if ( limits . eventId . minLeadingZeroBits > 0 ) {
@@ -89,33 +85,31 @@ export class EventMessageHandler implements IMessageHandler {
8985 }
9086 }
9187
92- if ( limits . pubkey . whitelist . length > 0 ) {
93- if ( ! limits . pubkey . whitelist . some ( ( prefix ) => event . pubkey . startsWith ( prefix ) ) ) {
94- return 'blocked: pubkey not allowed'
95- }
88+ if (
89+ limits . pubkey . whitelist . length > 0
90+ && ! limits . pubkey . whitelist . some ( ( prefix ) => event . pubkey . startsWith ( prefix ) )
91+ ) {
92+ return 'blocked: pubkey not allowed'
9693 }
9794
98- if ( limits . pubkey . blacklist . length > 0 ) {
99- if ( limits . pubkey . blacklist . some ( ( prefix ) => event . pubkey . startsWith ( prefix ) ) ) {
100- return 'blocked: pubkey not allowed'
101- }
95+ if (
96+ limits . pubkey . blacklist . length > 0
97+ && limits . pubkey . blacklist . some ( ( prefix ) => event . pubkey . startsWith ( prefix ) )
98+ ) {
99+ return 'blocked: pubkey not allowed'
102100 }
103101
104102 const isEventKindMatch = ( item : EventKinds | EventKindsRange ) =>
105103 typeof item === 'number'
106104 ? item === event . kind
107105 : event . kind >= item [ 0 ] && event . kind <= item [ 1 ]
108106
109- if ( limits . kind . whitelist . length > 0 ) {
110- if ( ! limits . kind . whitelist . some ( isEventKindMatch ) ) {
111- return `blocked: event kind ${ event . kind } not allowed`
112- }
107+ if ( limits . kind . whitelist . length > 0 && ! limits . kind . whitelist . some ( isEventKindMatch ) ) {
108+ return `blocked: event kind ${ event . kind } not allowed`
113109 }
114110
115- if ( limits . kind . blacklist . length > 0 ) {
116- if ( limits . kind . blacklist . some ( isEventKindMatch ) ) {
117- return `blocked: event kind ${ event . kind } not allowed`
118- }
111+ if ( limits . kind . blacklist . length > 0 && limits . kind . blacklist . some ( isEventKindMatch ) ) {
112+ return `blocked: event kind ${ event . kind } not allowed`
119113 }
120114 }
121115
@@ -152,13 +146,10 @@ export class EventMessageHandler implements IMessageHandler {
152146 )
153147 }
154148
155- const hits = await Promise . all (
156- rateLimits
157- . map ( async ( rateLimit ) => ( { ...rateLimit , active : await hit ( rateLimit ) } ) )
158- )
149+ const hits = await Promise . all ( rateLimits . map ( hit ) )
159150
160151 debug ( 'rate limit check %s: %o' , event . pubkey , hits )
161152
162- return hits . some ( ( { active } ) => active )
153+ return hits . some ( ( active ) => active )
163154 }
164155}
0 commit comments