0

我正在 Android/Java 中实现比特币协议。当我发送 getaddr 消息时,对等方会以警报消息响应

消息流如下:

  1. 发送版本消息
  2. 收到版本消息
  3. 发送一个verack消息
  4. 收到一条verack消息

当我尝试发送getaddr 消息时,我的对等方会以警报消息响应。

这是应用程序中逻辑的一小段代码:

 private void connect(Peer peer) {

    InetSocketAddress address = new InetSocketAddress(peer.ip, 8333);
    Socket socket = new Socket();
    try {
        socket.connect(address, 10000);

        OutputStream out = socket.getOutputStream();
        InputStream in = socket.getInputStream();

        // Step 1 - send version
        VersionMessage versionMessage = new VersionMessage();
        writeMessage(versionMessage, out);

        // Step 2 - read peer version
        VersionMessage peerVersionMessage = (VersionMessage) readMessage(in);

        // Step 3 - write verack
        VerAckMessage verAckMessage = new VerAckMessage();
        writeMessage(verAckMessage, out);

        // Step 4 - read verack
        VerAckMessage peerVerAckMessage = (VerAckMessage) readMessage(in);

        //Step 6 - read addr message (this does not happen, an alert is returned...)
        readMessage(in);

        writeMessage(getAddrMessage, out);

        out.close();
        in.close();
        socket.close();

    } catch (IOException e) {
        Log.i(App.TAG, "Socket failed to conenct");
    }
}

并且是一些日志的片段

connect to: 47.93.25.228:8333

writeMessage: version
readMessage: Version{version=70015, services=13,
timestamp=1518015001, addrRecv='null',
addrFrom='null', nonce=-2830171230962795176, 
userAgent='/Satoshi:0.15.1/', startHeight=508112, relay=true}

writeMessage: verack
readMessage: VerAckMessage{count=0, addrList=null}

writeMessage: getaddr
readMessage: alert {, version=1, relayUntil=0, expiration=2147483647,
id=2147483647, cancel=2147483646, setCancel=[2147483647], minVer=0, maxVer=2147483647, setSubVer=[], priority=2147483647, comment='', statusBar='URGENT: Alert key compromised, upgrade required', reserved=''}

如果我连续 4 次发送相同的 getaddr 消息 - 最终对方会回复一条 addr 消息(带有 1 个 addr - 他自己的地址)

4

1 回答 1

0

协议版本是:70012,将其撞到 70015 - 阻止对等方发送警报。

您可以在此处的参考客户端中找到更多信息: https ://github.com/bitcoin/bitcoin/blob/master/src/net_processing.cpp#L1707-L1711

 // If the peer is old enough to have the old alert system, send it the final alert.
    if (pfrom->nVersion <= 70012) {
        CDataStream finalAlert(ParseHex("60010000000000000000000000ffffff7f00000000ffffff7ffeffff7f01ffffff7f00000000ffffff7f00ffffff7f002f555247454e543a20416c657274206b657920636f6d70726f6d697365642c2075706772616465207265717569726564004630440220653febd6410f470f6bae11cad19c48413becb1ac2c17f908fd0fd53bdc3abd5202206d0e9c96fe88d4a0f01ed9dedae2b6f9e00da94cad0fecaae66ecf689bf71b50"), SER_NETWORK, PROTOCOL_VERSION);
        connman->PushMessage(pfrom, CNetMsgMaker(nSendVersion).Make("alert", finalAlert));
    }
于 2018-02-07T16:23:14.370 回答