Giter Club home page Giter Club logo

socketrouter's Introduction

SocketRouter

基于Socket来进行虚拟路由

运行测试

# 在项目根目录
python3 -m tests.five_node_test LS
python3 -m tests.five_node_test DV

结点配置文件

{
  "name": String,
  "node_id": Number,
  "ip": "$ip",
  "port": $port,
  "topo": {
    "$node_id": {
      "real_ip": "$ip",
      "real_port": $port,
      "cost": Number
    }
  }
}

协议

换行符使用 \n 而非 \r\n

基本协议形式

SRC_ID $源结点NODE_ID
DST_ID $目标结点NODE_ID,-1表示广播 $序列号,如果是广播需要序列号进行受控洪泛
$数据包类型(DATA/ROUTE/BEAT) $携带数据类型(TXT/JPEG/PNG/...)/$使用的算法模式(LS/DV)/$心跳(BEAT)
$数据,支持二进制

DATA类型

注意: 受UDP协议的限制,单个数据包的大小取决于操作系统所定义的发送/接收窗口的大小,如Windows中默认的大小是4KB-8KB,因此只能传输4KB以下的图片

文本:

SRC_ID 0
DST_ID 1
DATA TXT
Hello world, and this is the raw text data.
Feel free to use \n or \r\n here. It only depends on your application.
甚至可以写中文。

图片:

SRC_ID 0
DST_ID 1
DATA PNG
[Here should be the binary data]

ROUTE类型

LS模式路由信息

广播自身的邻居情况:

SRC_ID 0
DST_ID -1 132
ROUTE LS
$NODE_ID_0 $LINK_COST_0
$NDOE_ID_1 $LINK_COST_1
...

DV模式路由信息

向邻居发送自身的邻居情况

SRC_ID 0
DST_ID 1
ROUTE DV
$NODE_ID_0 $LINK_COST_0
$NDOE_ID_1 $LINK_COST_1
...

CLS模式路由信息

向普通结点发送已计算的转发表

SRC_ID 0
DST_ID -1 132
$NODE_ID_0 $NODE_ID_TO_0 $NODE_ID_VIA_0
$NODE_ID_0 $NODE_ID_TO_1 $NODE_ID_VIA_0
...

请求路由信息

向邻居发送路由信息请求

SRC_ID 0
DST_ID 1
ROUTE REQ
REQ

BEAT类型

广播心跳信息:

SRC_ID 0
DST_ID -1 123
BEAT BEAT
ALIVE

socketrouter's People

Contributors

daddytrap avatar sevennn avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.