Esempio n. 1
0
def client_handl_rev(data):
    global current_block
    print("客户端收到数据:" + data)
    global regist_status
    d_format = json.loads(data, object_hook=DataFormat.dict2DataFormat)
    if d_format.dataType == DEF_REGIST:  # 节点注册成功,则开启服务
        if d_format.param == "OK":
            regist_status = 0
        else:
            regist_status = -1
    elif d_format.dataType == DEF_ADDBLOCK:  # 增加节点
        print("not support the format type:" + d_format.dataType)
        print(d_format.param)
        block = json.loads(d_format.param, object_hook=Block.dict2Block)
        if current_block == "":  # 第一个block由中央服务器产生
            current_block = copy.deepcopy(block)
            print("复制区块成功"+ str(sys._getframe().f_lineno) )
            print(current_block.index)
        Block.server_add_block(block, current_block)
        print("添加区块成功")
    else:
        print("not support the format type:" + d_format.dataType)