@@ -135,150 +135,149 @@ func SetupSwagger() {
135
135
http .Handle ("/docs1" , sh1 )
136
136
}
137
137
138
- func WithBlobberRegisteredCondition (handler common.ReqRespHandlerf ) common.ReqRespHandlerf {
139
- logging .Logger .Info ("1Jayash acquired lock on check" )
140
- BlobberRegisteredMutex .Lock ()
141
- logging .Logger .Info ("2Jayash acquired lock on check" )
142
- if ! BlobberRegistered {
143
- logging .Logger .Info ("1Jayash condition met" )
144
- BlobberRegisteredMutex .Unlock ()
145
- logging .Logger .Info ("1Jayash released lock on check" )
146
- return func (w http.ResponseWriter , r * http.Request ) {
138
+ func WithBlobberRegistered (h http.Handler ) http.Handler {
139
+ if ! common .IsBlobberRegistered () {
140
+ return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
147
141
w .WriteHeader (http .StatusServiceUnavailable )
148
142
w .Write ([]byte ("Blobber not registered yet" ))
149
- }
143
+ })
150
144
}
151
145
152
- logging .Logger .Info ("Jayash condition failed" )
153
- BlobberRegisteredMutex .Unlock ()
154
- logging .Logger .Info ("Jayash released lock on check" )
155
- return handler
146
+ return h
156
147
}
157
148
158
149
/*setupHandlers sets up the necessary API end points */
159
150
func setupHandlers (r * mux.Router ) {
160
151
ConfigRateLimits ()
161
- r .Use (UseRecovery , UseCors )
152
+
153
+ s := r .NewRoute ().Subrouter ()
154
+ s .Use (UseRecovery , UseCors , WithBlobberRegistered )
155
+
156
+ s .HandleFunc ("/_stats" , RateLimitByCommmitRL (StatsHandler ))
162
157
163
158
//object operations
164
- r .HandleFunc ("/v1/connection/create/{allocation}" ,
165
- RateLimitByGeneralRL (WithBlobberRegisteredCondition ( common .ToJSONResponse (WithConnection (CreateConnectionHandler ) )))).
159
+ s .HandleFunc ("/v1/connection/create/{allocation}" ,
160
+ RateLimitByGeneralRL (common .ToJSONResponse (WithConnection (CreateConnectionHandler )))).
166
161
Methods (http .MethodPost )
167
162
168
- r .HandleFunc ("/v1/connection/redeem/{allocation}" ,
169
- RateLimitByGeneralRL (WithBlobberRegisteredCondition ( common .ToByteStream (WithConnection (RedeemHandler ) )))).
163
+ s .HandleFunc ("/v1/connection/redeem/{allocation}" ,
164
+ RateLimitByGeneralRL (common .ToByteStream (WithConnection (RedeemHandler )))).
170
165
Methods (http .MethodPost , http .MethodOptions )
171
166
172
- r .HandleFunc ("/v1/file/rename/{allocation}" ,
173
- RateLimitByGeneralRL (WithBlobberRegisteredCondition ( common .ToJSONResponse (WithConnection (RenameHandler ) )))).
167
+ s .HandleFunc ("/v1/file/rename/{allocation}" ,
168
+ RateLimitByGeneralRL (common .ToJSONResponse (WithConnection (RenameHandler )))).
174
169
Methods (http .MethodPost , http .MethodOptions )
175
170
176
- r .HandleFunc ("/v1/file/copy/{allocation}" ,
177
- RateLimitByGeneralRL (WithBlobberRegisteredCondition ( common .ToJSONResponse (WithConnection (CopyHandler ) )))).
171
+ s .HandleFunc ("/v1/file/copy/{allocation}" ,
172
+ RateLimitByGeneralRL (common .ToJSONResponse (WithConnection (CopyHandler )))).
178
173
Methods (http .MethodPost , http .MethodOptions )
179
174
180
- r .HandleFunc ("/v1/file/move/{allocation}" ,
181
- RateLimitByGeneralRL (WithBlobberRegisteredCondition ( common .ToJSONResponse (WithConnection (MoveHandler ) )))).
175
+ s .HandleFunc ("/v1/file/move/{allocation}" ,
176
+ RateLimitByGeneralRL (common .ToJSONResponse (WithConnection (MoveHandler )))).
182
177
Methods (http .MethodPost , http .MethodOptions )
183
178
184
- r .HandleFunc ("/v1/dir/{allocation}" ,
185
- RateLimitByGeneralRL (WithBlobberRegisteredCondition ( common .ToJSONResponse (WithConnection (CreateDirHandler ) )))).
179
+ s .HandleFunc ("/v1/dir/{allocation}" ,
180
+ RateLimitByGeneralRL (common .ToJSONResponse (WithConnection (CreateDirHandler )))).
186
181
Methods (http .MethodPost , http .MethodDelete , http .MethodOptions )
187
182
188
- r .HandleFunc ("/v1/connection/commit/{allocation}" ,
189
- RateLimitByCommmitRL (WithBlobberRegisteredCondition ( common .ToStatusCode (WithStatusConnectionForWM (CommitHandler ) ))))
183
+ s .HandleFunc ("/v1/connection/commit/{allocation}" ,
184
+ RateLimitByCommmitRL (common .ToStatusCode (WithStatusConnectionForWM (CommitHandler ))))
190
185
191
- r .HandleFunc ("/v1/connection/rollback/{allocation}" ,
192
- RateLimitByCommmitRL (WithBlobberRegisteredCondition ( common .ToStatusCode (WithStatusConnectionForWM (RollbackHandler ) ))))
186
+ s .HandleFunc ("/v1/connection/rollback/{allocation}" ,
187
+ RateLimitByCommmitRL (common .ToStatusCode (WithStatusConnectionForWM (RollbackHandler ))))
193
188
194
189
//object info related apis
195
- r .HandleFunc ("/allocation" ,
196
- RateLimitByGeneralRL (WithBlobberRegisteredCondition ( common .ToJSONResponse (WithConnection (AllocationHandler ) ))))
190
+ s .HandleFunc ("/allocation" ,
191
+ RateLimitByGeneralRL (common .ToJSONResponse (WithConnection (AllocationHandler ))))
197
192
198
- r .HandleFunc ("/v1/file/meta/{allocation}" ,
199
- RateLimitByGeneralRL (WithBlobberRegisteredCondition ( common .ToJSONResponse (WithReadOnlyConnection (FileMetaHandler ) ))))
193
+ s .HandleFunc ("/v1/file/meta/{allocation}" ,
194
+ RateLimitByGeneralRL (common .ToJSONResponse (WithReadOnlyConnection (FileMetaHandler ))))
200
195
201
- r .HandleFunc ("/v1/file/stats/{allocation}" ,
202
- RateLimitByGeneralRL (WithBlobberRegisteredCondition ( common .ToJSONResponse (WithReadOnlyConnection (FileStatsHandler ) ))))
196
+ s .HandleFunc ("/v1/file/stats/{allocation}" ,
197
+ RateLimitByGeneralRL (common .ToJSONResponse (WithReadOnlyConnection (FileStatsHandler ))))
203
198
204
- r .HandleFunc ("/v1/file/referencepath/{allocation}" ,
205
- RateLimitByObjectRL (WithBlobberRegisteredCondition ( common .ToJSONResponse (WithReadOnlyConnection (ReferencePathHandler ) ))))
199
+ s .HandleFunc ("/v1/file/referencepath/{allocation}" ,
200
+ RateLimitByObjectRL (common .ToJSONResponse (WithReadOnlyConnection (ReferencePathHandler ))))
206
201
207
- r .HandleFunc ("/v1/file/latestwritemarker/{allocation}" ,
208
- RateLimitByObjectRL (WithBlobberRegisteredCondition ( common .ToJSONResponse (WithReadOnlyConnection (WriteMarkerHandler ) ))))
202
+ s .HandleFunc ("/v1/file/latestwritemarker/{allocation}" ,
203
+ RateLimitByObjectRL (common .ToJSONResponse (WithReadOnlyConnection (WriteMarkerHandler ))))
209
204
210
- r .HandleFunc ("/v1/file/objecttree/{allocation}" ,
211
- RateLimitByObjectRL (WithBlobberRegisteredCondition ( common .ToStatusCode (WithStatusReadOnlyConnection (ObjectTreeHandler ) )))).
205
+ s .HandleFunc ("/v1/file/objecttree/{allocation}" ,
206
+ RateLimitByObjectRL (common .ToStatusCode (WithStatusReadOnlyConnection (ObjectTreeHandler )))).
212
207
Methods (http .MethodGet , http .MethodOptions )
213
208
214
- r .HandleFunc ("/v1/file/refs/{allocation}" ,
215
- RateLimitByGeneralRL (WithBlobberRegisteredCondition ( common .ToJSONResponse (WithReadOnlyConnection (RefsHandler ) )))).
209
+ s .HandleFunc ("/v1/file/refs/{allocation}" ,
210
+ RateLimitByGeneralRL (common .ToJSONResponse (WithReadOnlyConnection (RefsHandler )))).
216
211
Methods (http .MethodGet , http .MethodOptions )
217
212
218
- r .HandleFunc ("/v1/file/refs/recent/{allocation}" ,
219
- RateLimitByGeneralRL (WithBlobberRegisteredCondition ( common .ToJSONResponse (WithReadOnlyConnection (RecentRefsRequestHandler ) )))).
213
+ s .HandleFunc ("/v1/file/refs/recent/{allocation}" ,
214
+ RateLimitByGeneralRL (common .ToJSONResponse (WithReadOnlyConnection (RecentRefsRequestHandler )))).
220
215
Methods (http .MethodGet , http .MethodOptions )
221
216
222
217
// admin related
223
218
// Allowing admin api for debugging purpose only. Later on commented out line should be
224
219
// uncommented and line below it should be deleted
225
220
226
- r .HandleFunc ("/_debug" , common .AuthenticateAdmin (common .ToJSONResponse (DumpGoRoutines )))
227
- // r .HandleFunc("/_debug", RateLimitByCommmitRL(WithBlobberRegisteredCondition (common.ToJSONResponse(DumpGoRoutines)))
228
- r .HandleFunc ("/_config" , common .AuthenticateAdmin (common .ToJSONResponse (GetConfig )))
229
- // r .HandleFunc("/_config", RateLimitByCommmitRL(WithBlobberRegisteredCondition (common.ToJSONResponse(GetConfig)))
230
- // r .HandleFunc("/_stats", common.AuthenticateAdmin(StatsHandler)))
231
- r .HandleFunc ("/_stats" , RateLimitByCommmitRL (WithBlobberRegisteredCondition ( StatsHandler ) ))
221
+ s .HandleFunc ("/_debug" , common .AuthenticateAdmin (common .ToJSONResponse (DumpGoRoutines )))
222
+ // s .HandleFunc("/_debug", RateLimitByCommmitRL(common.ToJSONResponse(DumpGoRoutines)))
223
+ s .HandleFunc ("/_config" , common .AuthenticateAdmin (common .ToJSONResponse (GetConfig )))
224
+ // s .HandleFunc("/_config", RateLimitByCommmitRL(common.ToJSONResponse(GetConfig)))
225
+ // s .HandleFunc("/_stats", common.AuthenticateAdmin(StatsHandler)))
226
+ s .HandleFunc ("/_stats" , RateLimitByCommmitRL (StatsHandler ))
232
227
233
- r .HandleFunc ("/_logs" , RateLimitByCommmitRL (common .ToJSONResponse (GetLogs )))
228
+ s .HandleFunc ("/_logs" , RateLimitByCommmitRL (common .ToJSONResponse (GetLogs )))
234
229
235
- r .HandleFunc ("/_blobber_info" , RateLimitByCommmitRL (common .ToJSONResponse (GetBlobberInfo )))
236
-
237
- // r.HandleFunc("/_cleanupdisk", common.AuthenticateAdmin(common.ToJSONResponse(WithReadOnlyConnection(CleanupDiskHandler)))))
238
- // r.HandleFunc("/_cleanupdisk", RateLimitByCommmitRL(WithBlobberRegisteredCondition(common.ToJSONResponse(WithReadOnlyConnection(CleanupDiskHandler)))))
239
- r .HandleFunc ("/challengetimings" , WithBlobberRegisteredCondition (common .AuthenticateAdmin (common .ToJSONResponse (GetChallengeTimings ))))
240
- // r.HandleFunc("/challengetimings", RateLimitByCommmitRL(WithBlobberRegisteredCondition(common.ToJSONResponse(GetChallengeTimings)))
241
- r .HandleFunc ("/challenge-timings-by-challengeId" , RateLimitByCommmitRL (WithBlobberRegisteredCondition (common .ToJSONResponse (GetChallengeTiming ))))
230
+ // s.HandleFunc("/_cleanupdisk", common.AuthenticateAdmin(common.ToJSONResponse(WithReadOnlyConnection(CleanupDiskHandler)))))
231
+ // s.HandleFunc("/_cleanupdisk", RateLimitByCommmitRL(common.ToJSONResponse(WithReadOnlyConnection(CleanupDiskHandler)))))
232
+ s .HandleFunc ("/challengetimings" , common .AuthenticateAdmin (common .ToJSONResponse (GetChallengeTimings )))
233
+ // s.HandleFunc("/challengetimings", RateLimitByCommmitRL(common.ToJSONResponse(GetChallengeTimings)))
234
+ s .HandleFunc ("/challenge-timings-by-challengeId" , RateLimitByCommmitRL (common .ToJSONResponse (GetChallengeTiming )))
242
235
243
236
// Generate auth ticket
244
- r .HandleFunc ("/v1/auth/generate" , Authenticate0Box (common .ToJSONResponse (GenerateAuthTicket )))
237
+ s .HandleFunc ("/v1/auth/generate" , Authenticate0Box (common .ToJSONResponse (GenerateAuthTicket )))
245
238
246
239
//marketplace related
247
- r .HandleFunc ("/v1/marketplace/shareinfo/{allocation}" ,
248
- RateLimitByGeneralRL (WithBlobberRegisteredCondition ( common .ToJSONResponse (WithConnection (InsertShare ) )))).
240
+ s .HandleFunc ("/v1/marketplace/shareinfo/{allocation}" ,
241
+ RateLimitByGeneralRL (common .ToJSONResponse (WithConnection (InsertShare )))).
249
242
Methods (http .MethodOptions , http .MethodPost )
250
243
251
- r .HandleFunc ("/v1/marketplace/shareinfo/{allocation}" ,
252
- RateLimitByGeneralRL (WithBlobberRegisteredCondition ( common .ToJSONResponse (WithConnection (RevokeShare ) )))).
244
+ s .HandleFunc ("/v1/marketplace/shareinfo/{allocation}" ,
245
+ RateLimitByGeneralRL (common .ToJSONResponse (WithConnection (RevokeShare )))).
253
246
Methods (http .MethodOptions , http .MethodDelete )
254
247
255
248
// list files shared in this allocation
256
- r .HandleFunc ("/v1/marketplace/shareinfo/{allocation}" ,
257
- RateLimitByGeneralRL (WithBlobberRegisteredCondition ( common .ToJSONResponse (WithConnection (ListShare ) )))).
249
+ s .HandleFunc ("/v1/marketplace/shareinfo/{allocation}" ,
250
+ RateLimitByGeneralRL (common .ToJSONResponse (WithConnection (ListShare )))).
258
251
Methods (http .MethodOptions , http .MethodGet )
259
252
260
253
// lightweight http handler without heavy postgres transaction to improve performance
261
254
262
- r .HandleFunc ("/v1/writemarker/lock/{allocation}" ,
255
+ s .HandleFunc ("/v1/writemarker/lock/{allocation}" ,
263
256
RateLimitByGeneralRL (WithTxHandler (LockWriteMarker ))).
264
257
Methods (http .MethodPost , http .MethodOptions )
265
258
266
- r .HandleFunc ("/v1/writemarker/lock/{allocation}/{connection}" ,
259
+ s .HandleFunc ("/v1/writemarker/lock/{allocation}/{connection}" ,
267
260
RateLimitByGeneralRL (WithTxHandler (UnlockWriteMarker ))).
268
261
Methods (http .MethodDelete , http .MethodOptions )
269
262
270
263
// TODO: Deprecated, remove in future
271
- r .HandleFunc ("/v1/hashnode/root/{allocation}" ,
264
+ s .HandleFunc ("/v1/hashnode/root/{allocation}" ,
272
265
RateLimitByObjectRL (WithTxHandler (LoadRootHashnode ))).
273
266
Methods (http .MethodGet , http .MethodOptions )
274
267
275
- r .HandleFunc ("/v1/playlist/latest/{allocation}" ,
268
+ s .HandleFunc ("/v1/playlist/latest/{allocation}" ,
276
269
RateLimitByGeneralRL (WithTxHandler (LoadPlaylist ))).
277
270
Methods (http .MethodGet , http .MethodOptions )
278
271
279
- r .HandleFunc ("/v1/playlist/file/{allocation}" ,
272
+ s .HandleFunc ("/v1/playlist/file/{allocation}" ,
280
273
RateLimitByGeneralRL (WithTxHandler (LoadPlaylistFile ))).
281
274
Methods (http .MethodGet , http .MethodOptions )
275
+
276
+ r .HandleFunc ("/v1/file/list/{allocation}" ,
277
+ RateLimitByObjectRL (common .ToJSONResponse (WithReadOnlyConnection (ListHandler )))).
278
+ Methods (http .MethodGet , http .MethodOptions )
279
+ r .HandleFunc ("/v1/file/upload/{allocation}" , RateLimitByFileRL (common .ToJSONResponse (WithConnection (UploadHandler ))))
280
+ r .HandleFunc ("/v1/file/download/{allocation}" , RateLimitByFileRL (common .ToByteStream (WithConnection (DownloadHandler )))).Methods (http .MethodGet , http .MethodOptions )
282
281
}
283
282
284
283
func WithReadOnlyConnection (handler common.JSONResponderF ) common.JSONResponderF {
0 commit comments