Search in sources :

Example 1 with Capability

use of org.ethereum.net.client.Capability in project rskj by rsksmart.

the class PeerTest method testPeer.

/* PEER */
@Test
public void testPeer() {
    // Init
    InetAddress address = InetAddress.getLoopbackAddress();
    List<Capability> capabilities = new ArrayList<>();
    int port = 1010;
    String peerId = "1010";
    Peer peerCopy = new Peer(address, port, peerId);
    // Peer
    Peer peer = new Peer(address, port, peerId);
    // getAddress
    assertEquals("127.0.0.1", peer.getAddress().getHostAddress());
    // getPort
    assertEquals(port, peer.getPort());
    // getPeerId
    assertEquals(peerId, peer.getPeerId());
    // getCapabilities
    assertEquals(capabilities, peer.getCapabilities());
    // getEncoded
    assertEquals("CC847F0000018203F2821010C0", Hex.toHexString(peer.getEncoded()).toUpperCase());
    // toString
    assertEquals("[ip=" + address.getHostAddress() + " port=" + Integer.toString(port) + " peerId=" + peerId + "]", peer.toString());
    // equals
    assertEquals(true, peer.equals(peerCopy));
    assertEquals(false, peer.equals(null));
    // hashCode
    assertEquals(-1218913009, peer.hashCode());
}
Also used : Capability(org.ethereum.net.client.Capability) Peer(org.ethereum.net.p2p.Peer) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 2 with Capability

use of org.ethereum.net.client.Capability in project rskj by rsksmart.

the class SimpleConfigCapabilities method getConfigCapabilities.

@Override
public List<Capability> getConfigCapabilities() {
    List<Capability> capabilities = new ArrayList<>();
    capabilities.add(new Capability("rsk", (byte) 1));
    return capabilities;
}
Also used : Capability(org.ethereum.net.client.Capability) ArrayList(java.util.ArrayList)

Example 3 with Capability

use of org.ethereum.net.client.Capability in project rskj by rsksmart.

the class RLPTest method testEncodeHelloMessageCap0.

// capabilities: (eth:60, bzz:0, shh:2)
@Test
public void testEncodeHelloMessageCap0() {
    List<Capability> capabilities = new ArrayList<>();
    capabilities.add(new Capability("eth", (byte) 0x60));
    capabilities.add(new Capability("shh", (byte) 0x02));
    capabilities.add(new Capability("bzz", (byte) 0x00));
    HelloMessage helloMessage = new HelloMessage((byte) 4, "Geth/v0.9.29-4182e20e/windows/go1.4.2", capabilities, 30303, "a52205ce10b39be86507e28f6c3dc08ab4c3e8250e062ec47c6b7fa13cf4a4312d68d6c340315ef953ada7e19d69123a1b902ea84ec00aa5386e5d550e6c550e");
    byte[] rlp = helloMessage.getEncoded();
    HelloMessage helloMessage_ = new HelloMessage(rlp);
    String eth = helloMessage_.getCapabilities().get(0).getName();
    byte eth_60 = helloMessage_.getCapabilities().get(0).getVersion();
    assertEquals("eth", eth);
    assertEquals(0x60, eth_60);
    String shh = helloMessage_.getCapabilities().get(1).getName();
    byte shh_02 = helloMessage_.getCapabilities().get(1).getVersion();
    assertEquals("shh", shh);
    assertEquals(0x02, shh_02);
    String bzz = helloMessage_.getCapabilities().get(2).getName();
    byte bzz_00 = helloMessage_.getCapabilities().get(2).getVersion();
    assertEquals("bzz", bzz);
    assertEquals(0x00, bzz_00);
}
Also used : Capability(org.ethereum.net.client.Capability) HelloMessage(org.ethereum.net.p2p.HelloMessage) Test(org.junit.Test)

Example 4 with Capability

use of org.ethereum.net.client.Capability in project rskj by rsksmart.

the class HandshakeMessage method parse.

static HandshakeMessage parse(byte[] wire) {
    RLPList list = (RLPList) RLP.decode2(wire).get(0);
    HandshakeMessage message = new HandshakeMessage();
    Iterator<RLPElement> iter = list.iterator();
    // FIXME long
    message.version = ByteUtil.byteArrayToInt(iter.next().getRLPData());
    message.name = new String(iter.next().getRLPData(), Charset.forName("UTF-8"));
    // caps
    message.caps = Lists.newArrayList();
    for (RLPElement capEl : (RLPList) iter.next()) {
        RLPList capElList = (RLPList) capEl;
        String name = new String(capElList.get(0).getRLPData(), Charset.forName("UTF-8"));
        long version = ByteUtil.byteArrayToInt(capElList.get(1).getRLPData());
        // FIXME long
        message.caps.add(new Capability(name, (byte) version));
    }
    message.listenPort = ByteUtil.byteArrayToInt(iter.next().getRLPData());
    message.nodeId = iter.next().getRLPData();
    return message;
}
Also used : Capability(org.ethereum.net.client.Capability)

Example 5 with Capability

use of org.ethereum.net.client.Capability in project rskj by rsksmart.

the class MessageCodesResolver method init.

public void init(List<Capability> caps) {
    Collections.sort(caps);
    int offset = P2pMessageCodes.USER.asByte() + 1;
    for (Capability capability : caps) {
        if (capability.getName().equals(Capability.RSK)) {
            setEthOffset(offset);
            EthVersion v = fromCode(capability.getVersion());
            offset += EthMessageCodes.values(v).length;
        }
    }
}
Also used : Capability(org.ethereum.net.client.Capability) EthVersion(org.ethereum.net.eth.EthVersion)

Aggregations

Capability (org.ethereum.net.client.Capability)15 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)4 HelloMessage (org.ethereum.net.p2p.HelloMessage)3 InetAddress (java.net.InetAddress)1 ECKey (org.ethereum.crypto.ECKey)1 EthVersion (org.ethereum.net.eth.EthVersion)1 Peer (org.ethereum.net.p2p.Peer)1 RLPElement (org.ethereum.util.RLPElement)1 RLPList (org.ethereum.util.RLPList)1 Before (org.junit.Before)1