libp2p / jvm-libp2p

a libp2p implementation for the JVM, written in Kotlin 🔥
https://libp2p.io
Apache License 2.0
270 stars 75 forks source link

Lack of Documentations. #342

Closed lablnet closed 6 months ago

lablnet commented 11 months ago

The library contains a lot of functionality but unfortuality lacking the documentation.

Can anyone help me how I can implement PING in Kotlin?

The example given is for Java.

Another help would be good how to write 4 functions, subscribe to topic, unsubscribe to topic, sendMsgToTopic, ReciveMsgOnTopic.

### Tasks
lhDream commented 9 months ago
import io.libp2p.core.Host
import io.libp2p.core.dsl.host
import io.libp2p.core.multiformats.Multiaddr
import io.libp2p.protocol.Ping

fun main() {
    val port = 12345
    val host:Host = host{
        identity {
            random()
        }
        network {
            listen("/ip4/127.0.0.1/tcp/${port}")
        }
        protocols {
            + Ping()
        }
    }
    host.start().get()
    val remote = Multiaddr("/ip4/127.0.0.1/tcp/${port}/p2p/${host.peerId}")
    val ping = Ping().dial(host, remote).controller.get()
    println("Sending 5 ping messages to $remote")
    for(i in 0 until 5){
        val latency = ping.ping().get()
        println("ping $i latency: ${latency}ms")
    }
    host.stop().get()
}
Steve973 commented 5 months ago

I am looking for documentation, too. I need to do a lot more than ping, and I am using Java.