Alrighty, deploy
continuous-integration/drone/push Build was killed
Details
continuous-integration/drone/push Build was killed
Details
This commit is contained in:
parent
ca847a2bd9
commit
c09df22543
|
@ -1,5 +1,7 @@
|
||||||
# Proper-website p2p API
|
# Proper-website p2p API
|
||||||
|
|
||||||
|
[![Build Status](https://drone.dutchellie.nl/api/badges/DutchEllie/proper-website-p2p-api/status.svg?ref=refs/heads/main)](https://drone.dutchellie.nl/DutchEllie/proper-website-p2p-api)
|
||||||
|
|
||||||
The p2p part of the proper-website API.
|
The p2p part of the proper-website API.
|
||||||
Designed specifically to be ephemeral, and scalable.
|
Designed specifically to be ephemeral, and scalable.
|
||||||
As long as one node is online, it should be fine I think.
|
As long as one node is online, it should be fine I think.
|
||||||
|
|
24
src/main.go
24
src/main.go
|
@ -1,14 +1,12 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/libp2p/go-libp2p"
|
"github.com/libp2p/go-libp2p"
|
||||||
"github.com/libp2p/go-libp2p-core/host"
|
"github.com/libp2p/go-libp2p-core/host"
|
||||||
"github.com/libp2p/go-libp2p-core/network"
|
|
||||||
relayv1 "github.com/libp2p/go-libp2p/p2p/protocol/circuitv1/relay"
|
relayv1 "github.com/libp2p/go-libp2p/p2p/protocol/circuitv1/relay"
|
||||||
libp2pquic "github.com/libp2p/go-libp2p/p2p/transport/quic"
|
libp2pquic "github.com/libp2p/go-libp2p/p2p/transport/quic"
|
||||||
"github.com/libp2p/go-libp2p/p2p/transport/tcp"
|
"github.com/libp2p/go-libp2p/p2p/transport/tcp"
|
||||||
|
@ -56,28 +54,6 @@ func run() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
h1.SetStreamHandler("/echo/1.0.0", func(s network.Stream) {
|
|
||||||
log.Println("listener received new stream")
|
|
||||||
|
|
||||||
// Read whatever comes in and print it out
|
|
||||||
// from https://github.com/libp2p/go-libp2p/blob/621eafcecde611b27bbb42dda4b8bbc97b66e907/examples/echo/main.go#L197
|
|
||||||
if err := func(s network.Stream) error {
|
|
||||||
buf := bufio.NewReader(s)
|
|
||||||
str, err := buf.ReadString('\n')
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("error reading stream: %v\n", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
log.Printf("read: %s", str)
|
|
||||||
_, err = s.Write([]byte(str))
|
|
||||||
return err
|
|
||||||
}(s); err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
s.Reset()
|
|
||||||
} else {
|
|
||||||
s.Close()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
fullAddr := func(ha host.Host) string {
|
fullAddr := func(ha host.Host) string {
|
||||||
// Build host multiaddress
|
// Build host multiaddress
|
||||||
hostAddr, _ := ma.NewMultiaddr(fmt.Sprintf("/p2p/%s", ha.ID().Pretty()))
|
hostAddr, _ := ma.NewMultiaddr(fmt.Sprintf("/p2p/%s", ha.ID().Pretty()))
|
||||||
|
|
Loading…
Reference in New Issue