我正在 Android/Java 中实现比特币协议。当我发送 getaddr 消息时,对等方会以警报消息响应
消息流如下:
当我尝试发送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 - 他自己的地址)