コード例 #1
0
ファイル: PongMessage.java プロジェクト: crowne/ethereumj
  public static PongMessage create(byte[] token, String host, int port, ECKey privKey) {

    long expiration = 90 * 60 + System.currentTimeMillis() / 1000;

    byte[] rlpIp = RLP.encodeElement(host.getBytes());

    byte[] tmpPort = longToBytes(port);
    byte[] rlpPort = RLP.encodeElement(stripLeadingZeroes(tmpPort));
    byte[] rlpToList = RLP.encodeList(rlpIp, rlpPort, rlpPort);

    /* RLP Encode data */
    byte[] rlpToken = RLP.encodeElement(token);
    byte[] tmpExp = longToBytes(expiration);
    byte[] rlpExp = RLP.encodeElement(stripLeadingZeroes(tmpExp));

    byte[] type = new byte[] {2};
    byte[] data = RLP.encodeList(rlpToList, rlpToken, rlpExp);

    PongMessage pong = new PongMessage();
    pong.encode(type, data, privKey);

    pong.token = token;
    pong.expires = expiration;

    return pong;
  }
コード例 #2
0
ファイル: PongMessage.java プロジェクト: crowne/ethereumj
  static PongMessage create(byte[] token, ECKey privKey, long expiration) {

    /* RLP Encode data */
    byte[] rlpToken = RLP.encodeElement(token);
    byte[] rlpExp = RLP.encodeElement(ByteUtil.longToBytes(expiration));

    byte[] type = new byte[] {2};
    byte[] data = RLP.encodeList(rlpToken, rlpExp);

    PongMessage pong = new PongMessage();
    pong.encode(type, data, privKey);

    pong.token = token;
    pong.expires = expiration;

    return pong;
  }