Skip to content

Core ‐ Agent create new core

Bohdan Karpenko edited this page Apr 2, 2026 · 2 revisions

This handler is responsible for creating new cores in the system. It validates input, hashes the client certificate, and inserts a record into the database.


New Core Request

This request allows adding a new core with a unique IP and client identifier.

Request format

{
    "type": "request",
    "action": "new-core",
    "id": 1,
    "data": {
        "ip": "IP_ADDRESS",
        "name": "CORE_NAME",
        "client_cn": "CLIENT_COMMON_NAME"
    }
}

Fields

  • type: must be "request"

  • action: must be "new-core"

  • id: request identifier

  • data:

    • ip: string, required — IP address of the core
    • name: string, required — human-readable core name
    • client_cn: string, required — client certificate common name (used to generate client_hash)

Behavior

  • Validates that data exists and is correctly formatted

  • Converts client_cn to a hash using get_hash()

  • Inserts a new record into the cores table with:

    • ip
    • name
    • client_hash
  • Returns success or error depending on insertion result


Successful Response

{
    "type": "response",
    "id": 1,
    "status": "ok",
    "code": 200,
    "message": "Created successfully!"
}

Error Responses

Missing data

{
    "type": "response",
    "id": 1,
    "status": "error",
    "code": 400,
    "message": "Missing data"
}

Invalid request format

{
    "type": "response",
    "id": 1,
    "status": "error",
    "code": 400,
    "message": "Invalid new-core request"
}

Duplicate IP/Port

{
    "type": "response",
    "id": 1,
    "status": "error",
    "code": 409,
    "message": "Core with this IP and port already exists."
}

Internal server/database error

{
    "type": "response",
    "id": 1,
    "status": "error",
    "code": 500,
    "message": "Failed to create new core."
}

Status Enum

Possible values for status:

  • "ok" — core successfully created
  • "error" — creation failed

Notes

  • IP addresses must be unique in the system (constraint unique_ip_port)
  • client_cn is hashed before storage for security
  • The id field in the response matches the request id

Clone this wiki locally