Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Transport: NKN ? #147

Open
brailateo opened this issue Nov 27, 2020 · 4 comments
Open

New Transport: NKN ? #147

brailateo opened this issue Nov 27, 2020 · 4 comments
Assignees

Comments

@brailateo
Copy link

It might be interesting to add the NKN network as a new transport type.
The P2P messaging in NKN is working just fine behind NAT, there is a nkn-sdk-go package: https://github.com/nknorg/nkn-sdk-go

I was experimenting with NKN messaging in Go and JavaScript (browser and node) and it's fast, secure, reliable (using MultiClient) and free. The messaging is totally free , just pub-sub need a small amount of payment only on the pub side.

Simple example:

account, err := nkn.NewAccount()
if err != nil {
    log.Println("Error creating account NKN ", err)
}
fmt.Println("Seed = ",hex.EncodeToString(account.Seed()))
fmt.Println("PubKey = ", hex.EncodeToString(account.PubKey()))

numSubClients := 3
originalClient := false
config := nkn.GetDefaultClientConfig()

var err_nmc error

multiclient, err_nmc = nkn.NewMultiClient(account, "my_identity", numSubClients, originalClient,config)
if err_nmc != nil {
    log.Println("ERROR creating client NKN",err_nmc)
}

time.Sleep(time.Second)
<- multiclient.OnConnect.C
log.Println("Ready to send/receive messages")


response, err_send := multiclient.Send(nkn.NewStringArray("receiver_address"), "Ready to Babble?", nil)
if err_send != nil {
    log.Println("ERROR cannot send message ",err_send)
}

go func() {
    msg := <- response.C
    fmt.Println("Receive message from", msg.Src + ":", string(msg.Data))
}()

I think that this new transport can solve the NAT traversal and supply a better connectivity!
Best regards,
Constantin Teodorescu

@arrivets
Copy link
Contributor

Thanks that is very interesting. First time I here of NKN.
I ll have a look at it.

@brailateo
Copy link
Author

Any NKN node can run behind a router/firewall, no need for public IP or port forwarding.
Every NKN client has a Private/Public Key, (both can be restored from a previous saved seed) all I need in order to send/receive messages from othe NKN client is the Public Key.
Communication is encrypted and you can design distributed apps that are swarming private messages without any need of a VPN. I'm keeping with NKN a local database in sync with a remote "backup database" on a laptop that don't need a fixed IP address, today it's in a local network, tomorrow it can be in another place, no problem, when I start the "receiving updates" app, it just need a connection to internet because I have the same NKN address (restored from the seed saved in an encrypted database).

Babble could benefit from this kind of transport making possible to design a distributed app that manages to keep a consensus between far, distributed nodes.

Best regards,
Teo

@arrivets arrivets self-assigned this Apr 6, 2021
@arrivets arrivets mentioned this issue Apr 23, 2021
@arrivets
Copy link
Contributor

Hi @brailateo ,
FYI I have this PR to add the NKN network.
The integration was very easy but the connections seem very slow and unreliable.
You mentionned that you obtained fast and reliable results in your experiments.. I think I might be doing something wrong.. perhaps a bad configuration.

@brailateo
Copy link
Author

Yes, my tests were just fine, with <10ms round-trip packages between nodes, tested also with go, nodejs and JavaScript browser clients. On some rare occasions some nodes had connection problems because of some faulty DNS servers. If the problem persists, I think that you might get some support from NKN team on Discord, Yilun is a developer, a kind fellow ( skysniper ).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants