I want to write a new libp2p Transport. Inspired by the discussion and example in go-libp2p-transport-upgrader, I figured the easiest way to get started would be to implement a multiaddr-net address Filter, and then do something like this in my test program:
sStreamTransport := //what goes here??? - can I just use secio here?
sMuxTransport := //what goes here??? - can i just use yamux here?
upgrader := &tptu.Upgrader{
Protector: nil, // don't care about this
Secure: sStreamTransport,
Muxer: sMuxTransport,
Filters: filters, //will figure this out next once I have basic TCP example working
}
tcptrans := simpletransport.NewTCPTransport(upgrader)
opts := []libp2p.Option{
libp2p.Security("myfirsttransport",tcptrans),
[...]
}
Assuming this all sounds correct, my questions are those in the code above: (1) how do I instantiate secio? and (2) how do I instantiate a stream muxer?
I tried to answer question 1 on my own. Following the “stream security transport” link from the previously mentioned README.md, I wound up in go-libp2p-conn
(the repo of interfaces that secio implements), but that didn’t really help me figure out how to “instantiate a secio” in order to pass it into &Upgrader{}
's construction, so that I can then pass the Upgrader
into go-libp2p-transport-upgrader
.
The best example I could find was actually github.com/OpenBazaar/go-onion-transport, but that’s just the transport itself, not a demonstration of how to use that transport in code. To find that, you have to dig pretty deep into github.com/OpenBazaar/OpenBazaar-go (as noted in issue #1).
Any tips on how to proceed?