描述

本文章主上下两篇

  • 上篇:讲述以太坊devp2p与disc4节点发现协议
  • 下篇:实践篇,实现如何获取以太坊所有节点信息(ip,port,nodeId,client)

正文

本片为下篇:实践篇,主要描述如何获取以太坊所有节点信息(ip、port、nodeId、clientId)

因为以太坊创世块发展到如今,中间也有过很多次的迭代,所以通讯多少也有改变,这里不做一一说明,就以目前V62 V63 版本来做就可以了

根据上篇的理论知识,我们先理一下思路,如何去获取;

  1. 列出一组已备的节点ip地址,便于更好的快速的获取节点
  2. 定义基本数据结构,如 DHT、P2P Message(这里主要用到HelloMessage)、 disc v4 Message(ping、pong、findNode、Neighbors)、定义枚举做返回码与发送码
  3. 定义kademlia 结构,节点实体
  4. 按协议规定编写RLP、rlpx、Eckey 编码(此处参考以太坊源码),为后续协议之间通讯做编解码
  5. 遍历节点,
    • 利用disc v4 协议进行ping
    • 等待pong
    • find_Node 发出节点请求
    • Neighbors 获取节点信息nodes = [[ip, udp-port, tcp-port, node-id], ... ] 此处只能拿到ip、port、nodeId,clientId还未有
    • 将node 放入到nodetable 做缓存,nodetable存在阀值,当nodetable到达阀值则清除部分内容,保留部分(作用为去重复,提高效率,后期考虑效率可以尝试使用分布式获取节点信息,共享同一个nodetable缓存来提供效率)
    • 利用ip port nodeId,利用devp2p 协议与对方进行握手认证,并发送HelloMessage ,获取如下信息
    p2pVersion Specifies the implemented version of the P2P protocol. Now must be 1.
    clientId Specifies the client software identity, as a human-readable string (e.g. "Ethereum(++)/1.0.0").
    cap Specifies a peer capability name as an ASCII string, e.g. "eth" for the eth subprotocol.
    capVersion Specifies a peer capability version as a positive integer.
    listenPort specifies the port that the client is listening on (on the interface that the present connection traverses). If 0 it indicates the client is not listening.
    nodeId is the unique identity of the node and specifies a 512-bit secp256k1 public key that identifies this node.

因为这也是小编工作的内容,所以代码不方便开源,建议去看以太坊源码的net 层的代码

The Ethereum devp2p and discv4 protocol Part II的更多相关文章

  1. The Ethereum devp2p and discv4 protocol Part I

    描述 本文章分上下两篇 上篇:讲述以太坊devp2p与disc4节点发现协议 下篇:实践篇,实现如何获取以太坊所有节点信息(ip,port,nodeId,client,type,os) 正文 devp ...

  2. RChain节点通信机制(上)

    在介绍RChain的通信机制之前,先简单介绍一些以太坊的通信机制,它包括以下几个方面,如下详细了解以太坊的通信机制,可以查看https://github.com/ethereum/devp2p/blo ...

  3. 死磕以太坊源码分析之rlpx协议

    死磕以太坊源码分析之rlpx协议 本文主要参考自eth官方文档:rlpx协议 符号 X || Y:表示X和Y的串联 X ^ Y: X和Y按位异或 X[:N]:X的前N个字节 [X, Y, Z, ... ...

  4. RFC-TCP

    RFC: 793 TRANSMISSION CONTROL PROTOCOL DARPA INTERNET PROGRAM PROTOCOL SPECIFICATION September 1981 ...

  5. OBD Experts OBD II Software OBD II Protocol Stack

    http://www.obdexperts.co.uk/stack.html OBD II Software OBD Experts can provide you with ready to use ...

  6. ethereum/EIPs-1

    https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1.md 介绍了什么是EIP等等的详细信息: eip title status type a ...

  7. The MESI Protocol

    COMPUTER ORGANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION To provide cache cons ...

  8. Multiplexing SDIO Devices Using MAX II or CoolRunner-II CPLD

    XAPP906 Supporting Multiple SD Devices with CoolRunner-II CPLDs There has been an increasing demand ...

  9. Link Management Protocol (LMP)

    1.1. Link Management Protocol (LMP)   1.1.1.   Introduction and Theory The Link Manager (LM) transla ...

随机推荐

  1. 【网站公告】请大家不要发表任何涉及“得到App”的内容

    大家好,今天我们收到来自杭州某某网络科技有限公司的维权骑士团队的邮件,说他们受某某(天津)文化传播有限公司委托,展开维权.园子里有些博主因为学习“得到App”的课程在博客中记了一些笔记,也被维权. 为 ...

  2. IO模型介绍

    先理解几个问题: (1)为什么读取文件的时候,需要用户进程通过系统调用内核完成(系统不能自己调用内核)什么是用户态和内核态?为什么要区分内核态和用户态呢? 在 CPU 的所有指令中,有些指令是非常危险 ...

  3. xcode10下,Build Phases下没有Embed Frameworks

    升级xcode10后发现,Build Phases下,找不到Embed Frameworks了,最后发现在General下,有一项“Embedded Binaries",可以在这里添加Fra ...

  4. 使用.Net Core Mvc +SqlSugar +Autofac+AutoMapper+....

    开源地址:https://github.com/AjuPrince/Aju.Carefree 目前用到了 SqlSugar.Dapper.Autofac.AutoMapper.Swagger.Redi ...

  5. keras01 - hello world ~ 搭建第一个神经网络

    import numpy as np from keras.datasets import mnist from keras.models import Sequential, Model from ...

  6. Spring Boot 集成Swagger

    Spring Boot 集成Swagger - 小单的博客专栏 - CSDN博客https://blog.csdn.net/catoop/article/details/50668896 Spring ...

  7. echarts实时数据图表

    import React, { PureComponent } from 'react'; import ReactEcharts from 'echarts-for-react'; import m ...

  8. Quill 富文本编辑器

    Quill 富文本编辑器 https://quilljs.com/ https://github.com/quilljs/quill https://github.com/quilljs/awesom ...

  9. sonar 匿名内部类写法不推荐

    今天sonar扫出一个问题, 是这样说的. 我觉得有点牵强吧. 有点个人情绪在的样子. 那Java设计这种方式干嘛?

  10. js获取当前url

    1.window.location.href(设置或获取整个 URL 为字符串) 2.window.location.protocol(设置或获取 URL 的协议部分) 3.window.locati ...