比特币协议 GetAddr returns 警报消息
Bitcoin Protocol GetAddr returns Alert Message
我正在 Android/Java 中实现比特币协议。当我发送一条 getaddr 消息时,对等方回复一条警报消息
消息流为:
- 发送一个version message.
- 收到 version message.
- 发送一个verack message.
- 收到 verack message.
当我尝试发送 getaddr message, my peer responds with an alert message.
这是应用程序中逻辑的一小段代码:
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 个地址 - 他自己的地址)
协议版本为: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));
}
我正在 Android/Java 中实现比特币协议。当我发送一条 getaddr 消息时,对等方回复一条警报消息
消息流为:
- 发送一个version message.
- 收到 version message.
- 发送一个verack message.
- 收到 verack message.
当我尝试发送 getaddr message, my peer responds with an alert message.
这是应用程序中逻辑的一小段代码:
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 个地址 - 他自己的地址)
协议版本为: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));
}