sdlan-rs/docs/http_api.md
2024-06-20 23:02:44 +08:00

4.9 KiB
Raw Blame History

sdlan中心节点提供的api

sdlan中心节点需要被告知的内容主要有

  • register_token——节点上线需要填写的token是一个big int64位的unsigned int
  • register_token关联的信息,包括(但不一定需要)
    • 过期时间
    • 默认加入的网络
  • register_token关联的用户信息,主要包括
    • 用户的uuid为一个big int(64位的unsigned int)
    • 用户是否启用
    • 与用户uuid相互关联的信息比如该用户限制的连接的终端的个数等如果有的化

1.0. token创建通知

POST /token/created

{
    "value": $unsigned_int,

    // 过期时候的unix timestamp
    "expire": $unsigned_int,

    // 默认加入的网络的uuid
    "defalut_network_id": "",

    "user_info": {
        // 关联的用户的id的数字
        "user_id": $unsigned_int,
        // 限制的节点的个数
        "peer_limit": $int,
        // 表明用户是否启用
        "enabled": $bool,
    }
}

返回值:

{
    // 0表示成功其他数字代表失败
    "code": $int,
    // 如果成功message返回信息这里只返回一个ok
    "message": "ok",
    // 如果code不为0则error表示出错信息
    "error": $string,
}

1.1. token删除

通过调用该接口告知supernode删除一个token。

POST /token/deleted

{
    "value": $unsigned_int,
}

返回值:

{
    // 0表示成功其他数字代表失败
    "code": $int,
    // 如果成功message返回信息这里只返回一个ok
    "message": "ok",
    // 如果code不为0则error表示出错信息
    "error": $string,
}

1.2. 用户信息修改

用户信息修改,主要涉及到用户可以创建节点的个数,接口如下:

POST /user/updated

{
    "user_id": $unsigned_int,
    "peer_limit": $int,
    "enabled": $bool
}

返回值:

{
    // 0表示成功其他数字代表失败
    "code": $int,
    // 如果成功message返回信息这里只返回一个ok
    "message": "ok",
    // 如果code不为0则error表示出错信息
    "error": $string,
}

1.3. 创建网络

创建网络是supernode端进行主要因为需要分配ip地址supernode端提供创建网络的api。

POST /network/create

{
    // 网络的名称
    "name": $string,
    // 用户选择的ip地址段cidr格式的ip地址如10.20.1.0/24
    //  如果不指定,则该字段不传递
    "ip": $string,
    // 创建的用户的id最后会用于表明该网络属于哪个用户
    "user_id": $unsigned_int,
}

返回值:

{
    // 0表示成功其他数字代表失败
    "code": $int,
    // 如果成功message返回信息这里只返回一个ok
    "message": {
        // 该网络的唯一标识
        "uuid": $string
        // 最后分配的cidr格式的ip地址如10.20.1.0/24
        "ip": $string
    },
    // 如果code不为0则error表示出错信息
    "error": $string,
}

1.4. 移动节点

移动节点用于将某个处于网络A中的节点移动到同一个用户的另一个网络B中

POST /peer/move

{
    // 需要移动的节点的uuid
    "peer_id": $string,
    // 节点所处的以前的网络
    "from_id": $string,
    // 节点移动到的新网络的uuid
    "to_id": $string,
    // 属于哪个用户
    "user_id": $unsigned_int,
}

返回值:

{
    // 0表示成功其他数字代表失败
    "code": $int,
    // 如果成功message返回信息这里只返回一个ok
    "message": "ok",
    // 如果code不为0则error表示出错信息
    "error": $string
}

1.5. 授权节点

移动节点用于将某个处于未授权的节点,移动到同一个用户的某个网络中:

POST /peer/authorize

{
    // 需要移动的节点的uuid
    "peer_id": $string,
    // 节点移动到的新网络的uuid
    "to_id": $string,
    // 属于哪个用户
    "user_id": $unsigned_int,
}

返回值:

{
    // 0表示成功其他数字代表失败
    "code": $int,
    // 如果成功message返回信息这里只返回一个ok
    "message": "ok",
    // 如果code不为0则error表示出错信息
    "error": $string
}

1.6. 取消节点授权

移动节点用于将某个处于某个网络的节点,取消授权,返回到为授权状态:

POST /peer/unauthorize

{
    // 需要移动的节点的uuid
    "peer_id": $string,
    // 节点所处的以前的网络
    "from_id": $string,
    // 属于哪个用户
    "user_id": $unsigned_int,
}

返回值:

{
    // 0表示成功其他数字代表失败
    "code": $int,
    // 如果成功message返回信息这里只返回一个ok
    "message": "ok",
    // 如果code不为0则error表示出错信息
    "error": $string
}

2.0 sdlan中心节点使用的数据库结构

在中心节点收到客户端上线请求之后,如果这个节点是第一次上线,则会将相关信息插入到