Merge branch 'master' into feature/blockexc-prevent-retransmit

This commit is contained in:
Ben Bierens 2025-02-05 09:02:28 +01:00 committed by GitHub
commit 9db7abb61c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 35 additions and 7 deletions

View File

@ -179,7 +179,7 @@ proc initDataApi(node: CodexNodeRef, repoStore: RepoStore, router: var RestRoute
trace "Handling file upload" trace "Handling file upload"
var bodyReader = request.getBodyReader() var bodyReader = request.getBodyReader()
if bodyReader.isErr(): if bodyReader.isErr():
return RestApiResponse.error(Http500) return RestApiResponse.error(Http500, msg = bodyReader.error())
# Attempt to handle `Expect` header # Attempt to handle `Expect` header
# some clients (curl), wait 1000ms # some clients (curl), wait 1000ms
@ -190,10 +190,13 @@ proc initDataApi(node: CodexNodeRef, repoStore: RepoStore, router: var RestRoute
var mimetype = request.headers.getString(ContentTypeHeader).some var mimetype = request.headers.getString(ContentTypeHeader).some
if mimetype.get() != "": if mimetype.get() != "":
let mimetypeVal = mimetype.get()
var m = newMimetypes() var m = newMimetypes()
let extension = m.getExt(mimetype.get(), "") let extension = m.getExt(mimetypeVal, "")
if extension == "": if extension == "":
return RestApiResponse.error(Http422, "The MIME type is not valid.") return RestApiResponse.error(
Http422, "The MIME type '" & mimetypeVal & "' is not valid."
)
else: else:
mimetype = string.none mimetype = string.none
@ -231,9 +234,6 @@ proc initDataApi(node: CodexNodeRef, repoStore: RepoStore, router: var RestRoute
finally: finally:
await reader.closeWait() await reader.closeWait()
trace "Something went wrong error"
return RestApiResponse.error(Http500)
router.api(MethodGet, "/api/codex/v1/data") do() -> RestApiResponse: router.api(MethodGet, "/api/codex/v1/data") do() -> RestApiResponse:
let json = await formatManifestBlocks(node) let json = await formatManifestBlocks(node)
return RestApiResponse.response($json, contentType = "application/json") return RestApiResponse.response($json, contentType = "application/json")

View File

@ -9,6 +9,34 @@ if [[ -n "${ENV_PATH}" ]]; then
set +a set +a
fi fi
# Bootstrap node from URL
if [[ -n "${BOOTSTRAP_NODE_URL}" ]]; then
BOOTSTRAP_NODE_URL="${BOOTSTRAP_NODE_URL}/api/codex/v1/spr"
WAIT=${BOOTSTRAP_NODE_URL_WAIT:-300}
SECONDS=0
SLEEP=1
# Run and retry if fail
while (( SECONDS < WAIT )); do
SPR=$(curl -s -f -m 5 -H 'Accept: text/plain' "${BOOTSTRAP_NODE_URL}")
# Check if exit code is 0 and returned value is not empty
if [[ $? -eq 0 && -n "${SPR}" ]]; then
export CODEX_BOOTSTRAP_NODE="${SPR}"
echo "Bootstrap node: CODEX_BOOTSTRAP_NODE=${CODEX_BOOTSTRAP_NODE}"
break
else
# Sleep and check again
echo "Can't get SPR from ${BOOTSTRAP_NODE_URL} - Retry in $SLEEP seconds / $((WAIT - SECONDS))"
sleep $SLEEP
fi
done
fi
# Stop Codex run if unable to get SPR
if [[ -n "${BOOTSTRAP_NODE_URL}" && -z "${CODEX_BOOTSTRAP_NODE}" ]]; then
echo "Unable to get SPR from ${BOOTSTRAP_NODE_URL} in ${BOOTSTRAP_NODE_URL_WAIT} seconds - Stop Codex run"
exit 1
fi
# Parameters # Parameters
if [[ -z "${CODEX_NAT}" ]]; then if [[ -z "${CODEX_NAT}" ]]; then
if [[ "${NAT_IP_AUTO}" == "true" && -z "${NAT_PUBLIC_IP_AUTO}" ]]; then if [[ "${NAT_IP_AUTO}" == "true" && -z "${NAT_PUBLIC_IP_AUTO}" ]]; then

View File

@ -200,7 +200,7 @@ twonodessuite "REST API":
let response = client1.uploadRaw("some file contents", headers) let response = client1.uploadRaw("some file contents", headers)
check response.status == "422 Unprocessable Entity" check response.status == "422 Unprocessable Entity"
check response.body == "The MIME type is not valid." check response.body == "The MIME type 'hello/world' is not valid."
test "node retrieve the metadata", twoNodesConfig: test "node retrieve the metadata", twoNodesConfig:
let headers = newHttpHeaders( let headers = newHttpHeaders(