bloxbean / yaci

A Cardano Mini Protocols implementation in Java
MIT License
25 stars 3 forks source link

Error when trying to connect to releay node #4

Closed mcwalina closed 1 year ago

mcwalina commented 1 year ago

Hi, I tried connect to my local relay node using: LocalClientProvider localClientProvider = new LocalClientProvider("192.168.43.156", 6000, protocolMagic); localClientProvider.start();

but I getting error:

2023-01-17T08:33:48.651+01:00  INFO 5176 --- [tLoopGroup-2-48] c.b.cardano.yaci.core.network.Session    : Connection established
2023-01-17T08:33:48.651+01:00  INFO 5176 --- [tLoopGroup-2-48] c.b.c.yaci.core.network.NodeClient       : Connected !!!
2023-01-17T08:33:48.652+01:00  WARN 5176 --- [tLoopGroup-2-48] i.netty.channel.DefaultChannelPipeline   : An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.

java.net.SocketException: Connection reset
        at java.base/sun.nio.ch.SocketChannelImpl.throwConnectionReset(SocketChannelImpl.java:401) ~[na:na]
        at java.base/sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:434) ~[na:na]
        at io.netty.buffer.PooledByteBuf.setBytes(PooledByteBuf.java:259) ~[netty-buffer-4.1.86.Final.jar:4.1.86.Final]
        at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1132) ~[netty-buffer-4.1.86.Final.jar:4.1.86.Final]
        at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:357) ~[netty-transport-4.1.86.Final.jar:4.1.86.Final]
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:151) ~[netty-transport-4.1.86.Final.jar:4.1.86.Final]
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788) ~[netty-transport-4.1.86.Final.jar:4.1.86.Final]
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724) ~[netty-transport-4.1.86.Final.jar:4.1.86.Final]
        at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650) ~[netty-transport-4.1.86.Final.jar:4.1.86.Final]
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562) ~[netty-transport-4.1.86.Final.jar:4.1.86.Final]
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[netty-common-4.1.86.Final.jar:4.1.86.Final]
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.86.Final.jar:4.1.86.Final]
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.86.Final.jar:4.1.86.Final]
        at java.base/java.lang.Thread.run(Thread.java:1589) ~[na:na]

2023-01-17T08:33:48.652+01:00  INFO 5176 --- [tLoopGroup-2-48] c.b.c.yaci.core.network.NodeClient       : Connection closed !!!

Logs from relay node: {"app":[],"at":"2023-01-17T07:33:50.85Z","data":{"address":"192.168.43.114:59592","event":"ErrorPolicySuspendConsumer (Just (ApplicationExceptionTrace (HandshakeError (VersionMismatch [NodeToNodeV_7,NodeToNodeV_8,NodeToNodeV_9] [])))) 200s","kind":"ErrorPolicyTrace"},"env":"1.35.4:ebc7b","host":"rnode","loc":null,"msg":"","ns":["cardano.node.ErrorPolicy"],"pid":"1249","sev":"Notice","thread":"215"}

satran004 commented 1 year ago

@mcwalina It seems you are connecting to node-to-node protocol port which is 6000.

As LocalClientProvider uses node-to-client protocol which is accessible through nodeSocketFile (Unix domain socket), you have to use the following constructor

new LocalClientProvider(nodeSocketFile, protocolMagic)

Alternatively, you can expose nodeSocketFile (Unix Domain Socket) through a relay like 'socket' using tcp host/port, then you can use the other constructor to access remotely.

mcwalina commented 1 year ago

@satran004 You are right. Exposing socket file by tcp and connecting to it did a job.

socat TCP-LISTEN:3001,fork,reuseaddr, UNIX-CONNECT:/opt/cardano/cnode/sockets/node.socket

LocalClientProvider localClientProvider = new LocalClientProvider("192.168.43.156", 3001, protocolMagic);

2023-01-17T16:40:17.426+01:00  INFO 18828 --- [ntLoopGroup-2-1] c.b.cardano.yaci.core.network.Session    : Connection established
2023-01-17T16:40:17.426+01:00  INFO 18828 --- [ntLoopGroup-2-1] c.b.c.yaci.core.network.NodeClient       : Connected !!!
2023-01-17T16:40:17.431+01:00  INFO 18828 --- [ntLoopGroup-2-1] c.b.c.y.c.p.handshake.HandshakeAgent     : Handshake Ok!!! AcceptVersion(versionNumber=32781, versionData=N2CVersionData{networkMagic=764824073})

Thanks for you help and your contribution.