Search in sources :

Example 16 with NodeInfo

use of com.icodici.universa.node2.NodeInfo in project universa by UniversaBlockchain.

the class NetworkV2 method unpack.

private List<Notification> unpack(byte[] packedNotifications) throws IOException {
    List<Notification> nn = new ArrayList<>();
    try {
        // packet type code
        Boss.Reader r = new Boss.Reader(packedNotifications);
        if (r.readInt() != 1)
            throw new IOException("invalid packed notification type code");
        // from node number
        int number = r.readInt();
        NodeInfo from = getInfo(number);
        if (from == null)
            throw new IOException(myInfo.getNumber() + ": unknown node number: " + number);
        // number of notifications in the packet
        int count = r.readInt();
        if (count < 0 || count > 1000)
            throw new IOException("unvalid packed notifications count: " + count);
        for (int i = 0; i < count; i++) {
            nn.add(Notification.read(from, r));
        }
        return nn;
    } catch (Exception e) {
        // e.printStackTrace();
        report(getLabel(), "failed to unpack notification: " + e, DatagramAdapter.VerboseLevel.BASE);
        throw new IOException("failed to unpack notifications", e);
    }
}
Also used : Boss(net.sergeych.boss.Boss) NodeInfo(com.icodici.universa.node2.NodeInfo) IOException(java.io.IOException) Notification(com.icodici.universa.node2.Notification) IOException(java.io.IOException)

Aggregations

NodeInfo (com.icodici.universa.node2.NodeInfo)16 NetConfig (com.icodici.universa.node2.NetConfig)14 SymmetricKey (com.icodici.crypto.SymmetricKey)13 ArrayList (java.util.ArrayList)13 Test (org.junit.Test)11 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)9 Random (java.util.Random)5 TimeoutException (java.util.concurrent.TimeoutException)5 AsyncEvent (net.sergeych.tools.AsyncEvent)5 Arrays.asList (java.util.Arrays.asList)4 List (java.util.List)4 PooledDb (com.icodici.db.PooledDb)2 SQLException (java.sql.SQLException)2 PrivateKey (com.icodici.crypto.PrivateKey)1 Notification (com.icodici.universa.node2.Notification)1 IOException (java.io.IOException)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 Boss (net.sergeych.boss.Boss)1