support different pubsub implementation

add LICENSE file

Signed-off-by: Leo Chen <leo@harmony.one>
pull/425/head
Leo Chen 6 years ago
parent 504472832d
commit 42aa5aa04c
  1. 22
      test/p2pchat/LICENSE
  2. 17
      test/p2pchat/chat.go
  3. 2
      test/p2pchat/flags.go

@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2018 Protocol Labs
Copyright (c) 2019 Harmony.One
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

@ -21,6 +21,7 @@ import (
var logger = log.Logger("rendezvous")
// Harmony MIT License
func writePubsub(ps *pubsub.PubSub) {
stdReader := bufio.NewReader(os.Stdin)
for {
@ -30,6 +31,7 @@ func writePubsub(ps *pubsub.PubSub) {
}
}
// Harmony MIT License
func readPubsub(sub *pubsub.Subscription) {
ctx := context.Background()
for {
@ -121,10 +123,23 @@ func main() {
panic(err)
}
ps, err := pubsub.NewFloodSub(ctx, host)
var ps *pubsub.PubSub
switch config.PubSubImpl {
case "gossip":
ps, err = pubsub.NewGossipSub(ctx, host)
case "flood":
ps, err = pubsub.NewFloodSub(ctx, host)
default:
logger.Error("Unsupported Pubsub implementation")
return
}
if err != nil {
fmt.Printf("pubsub error: %v", err)
panic(err)
}
sub, err := ps.Subscribe("pubsubtestchannel")
go writePubsub(ps)

@ -50,6 +50,7 @@ type Config struct {
BootstrapPeers addrList
ListenAddresses addrList
ProtocolID string
PubSubImpl string
}
// ParseFlags ...
@ -60,6 +61,7 @@ func ParseFlags() (Config, error) {
flag.Var(&config.BootstrapPeers, "peer", "Adds a peer multiaddress to the bootstrap list")
flag.Var(&config.ListenAddresses, "listen", "Adds a multiaddress to the listen list")
flag.StringVar(&config.ProtocolID, "pid", "/chat/1.1.0", "Sets a protocol id for stream headers")
flag.StringVar(&config.PubSubImpl, "pubsub", "gossip", "Set the pubsub implementation: gossip, flood")
flag.Parse()
if len(config.BootstrapPeers) == 0 {

Loading…
Cancel
Save