Polish message creation
This commit is contained in:
parent
8af4556a4f
commit
841c4adb62
|
@ -1,18 +1,23 @@
|
|||
package org.ethereum.net.rlpx;
|
||||
|
||||
import org.ethereum.crypto.ECKey;
|
||||
import org.ethereum.util.ByteUtil;
|
||||
import org.ethereum.util.RLP;
|
||||
|
||||
import static org.ethereum.util.ByteUtil.longToBytes;
|
||||
import static org.ethereum.util.ByteUtil.stripLeadingZeroes;
|
||||
|
||||
public class FindNodeMessage extends Message {
|
||||
|
||||
public static Message create(byte[] target, ECKey privKey) {
|
||||
|
||||
long expiration = System.currentTimeMillis();
|
||||
long expiration = 3 + System.currentTimeMillis() / 1000;
|
||||
|
||||
|
||||
/* RLP Encode data */
|
||||
byte[] rlpToken = RLP.encodeElement(target);
|
||||
byte[] rlpExp = RLP.encodeElement(ByteUtil.longToBytes(expiration));
|
||||
|
||||
byte[] tmpExp = longToBytes(expiration);
|
||||
byte[] rlpExp = RLP.encodeElement(stripLeadingZeroes(tmpExp));
|
||||
|
||||
byte[] type = new byte[]{3};
|
||||
byte[] data = RLP.encodeList(rlpToken, rlpExp);
|
||||
|
|
|
@ -12,13 +12,15 @@ public class NeighborsMessage extends Message {
|
|||
|
||||
long expiration = System.currentTimeMillis();
|
||||
|
||||
byte[][] nodeRLPs = new byte[nodes.size()][];
|
||||
byte[][] nodeRLPs = null;
|
||||
|
||||
/* RLP Encode data */
|
||||
int i = 0;
|
||||
for (Node node : nodes){
|
||||
nodeRLPs[i] = node.getRLP();
|
||||
++i;
|
||||
if (nodes != null) {
|
||||
nodeRLPs = new byte[nodes.size()][];
|
||||
int i = 0;
|
||||
for (Node node : nodes) {
|
||||
nodeRLPs[i] = node.getRLP();
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
byte[] rlpListNodes = RLP.encodeList(nodeRLPs);
|
||||
|
|
|
@ -1,19 +1,25 @@
|
|||
package org.ethereum.net.rlpx;
|
||||
|
||||
import org.ethereum.crypto.ECKey;
|
||||
import org.ethereum.util.ByteUtil;
|
||||
import org.ethereum.util.RLP;
|
||||
|
||||
import static org.ethereum.util.ByteUtil.longToBytes;
|
||||
import static org.ethereum.util.ByteUtil.stripLeadingZeroes;
|
||||
|
||||
public class PingMessage extends Message {
|
||||
|
||||
public static Message create(String ip, int port, ECKey privKey){
|
||||
|
||||
long expiration = System.currentTimeMillis();
|
||||
long expiration = 3 + System.currentTimeMillis() / 1000;
|
||||
|
||||
/* RLP Encode data */
|
||||
byte[] rlpIp = RLP.encodeElement(ip.getBytes());
|
||||
byte[] rlpPort = RLP.encodeElement(ByteUtil.longToBytes(port));
|
||||
byte[] rlpExp = RLP.encodeElement(ByteUtil.longToBytes(expiration));
|
||||
|
||||
byte[] tmpPort = longToBytes(port);
|
||||
byte[] rlpPort = RLP.encodeElement(stripLeadingZeroes(tmpPort));
|
||||
|
||||
byte[] tmpExp = longToBytes(expiration);
|
||||
byte[] rlpExp = RLP.encodeElement(stripLeadingZeroes(tmpExp));
|
||||
|
||||
byte[] type = new byte[]{1};
|
||||
byte[] data = RLP.encodeList(rlpIp, rlpPort, rlpExp);
|
||||
|
|
Loading…
Reference in New Issue