-
Notifications
You must be signed in to change notification settings - Fork 186
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
Allow peer to be in Relay ONLY mode for a topic #208
Closed
aarshkshah1992
wants to merge
1
commit into
libp2p:master
from
aarshkshah1992:feat/separate-subscribe-relay
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -363,6 +363,145 @@ func TestGossipsubGossip(t *testing.T) { | |
time.Sleep(time.Second * 2) | ||
} | ||
|
||
func TestRelayOnlyPeerForwardsMessage(t *testing.T) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
hosts := getNetHosts(t, ctx, 8) | ||
psubs := getPubsubs(ctx, hosts) | ||
|
||
connect(t, hosts[0], hosts[1]) | ||
connect(t, hosts[1], hosts[2]) | ||
connect(t, hosts[2], hosts[3]) | ||
connect(t, hosts[1], hosts[4]) | ||
|
||
connect(t, hosts[0], hosts[5]) | ||
connect(t, hosts[5], hosts[6]) | ||
connect(t, hosts[6], hosts[7]) | ||
/* | ||
R= Relay ONLY | ||
S = Subscriber | ||
|
||
[0](R) -> [1](R) -> [2](R) -> [3](S) | ||
| L->[4](S) | ||
v | ||
[5](R) | ||
| | ||
v | ||
[6](R) -> [7](S) | ||
*/ | ||
|
||
var subs []*Subscription | ||
for i, ps := range psubs { | ||
if i == 3 || i == 4 || i == 7 { | ||
ch, err := ps.Subscribe("foo") | ||
if err != nil { | ||
panic(err) | ||
} | ||
subs = append(subs, ch) | ||
} else { | ||
_, err := ps.Join("foo") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
} | ||
|
||
// wait for heartbeats to build mesh | ||
time.Sleep(time.Second * 2) | ||
|
||
// assert that published message is received | ||
for i := 0; i < 100; i++ { | ||
msg := []byte(fmt.Sprintf("%d it's not a floooooood %d", i, i)) | ||
|
||
owner := rand.Intn(len(psubs)) | ||
|
||
psubs[owner].Publish("foo", msg) | ||
|
||
for _, sub := range subs { | ||
got, err := sub.Next(ctx) | ||
if err != nil { | ||
t.Fatal(sub.err) | ||
} | ||
if !bytes.Equal(msg, got.Data) { | ||
t.Fatal("got wrong message!") | ||
} | ||
} | ||
} | ||
} | ||
|
||
func TestGossipsubGossipWithSomeRelayOnlyPeers(t *testing.T) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
hosts := getNetHosts(t, ctx, 15) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change number of hosts to 20 for consistency. |
||
|
||
psubs := getGossipsubs(ctx, hosts) | ||
|
||
subscribeToTopic := func(topic string) []*Subscription { | ||
var msgs []*Subscription | ||
|
||
for i, ps := range psubs { | ||
if i%4 != 0 { | ||
subch, err := ps.Subscribe(topic) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
msgs = append(msgs, subch) | ||
} else { | ||
_, err := ps.Join(topic) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
} | ||
return msgs | ||
} | ||
|
||
msgs := subscribeToTopic("foobar") | ||
xmsgs := subscribeToTopic("bazcrux") | ||
|
||
denseConnect(t, hosts) | ||
|
||
// wait for heartbeats to build mesh | ||
time.Sleep(time.Second * 2) | ||
|
||
for i := 0; i < 100; i++ { | ||
msg := []byte(fmt.Sprintf("%d it's not a floooooood %d", i, i)) | ||
|
||
owner := rand.Intn(len(psubs)) | ||
|
||
psubs[owner].Publish("foobar", msg) | ||
psubs[owner].Publish("bazcrux", msg) | ||
|
||
for _, sub := range msgs { | ||
got, err := sub.Next(ctx) | ||
if err != nil { | ||
t.Fatal(sub.err) | ||
} | ||
if !bytes.Equal(msg, got.Data) { | ||
t.Fatal("got wrong message!") | ||
} | ||
} | ||
|
||
for _, sub := range xmsgs { | ||
got, err := sub.Next(ctx) | ||
if err != nil { | ||
t.Fatal(sub.err) | ||
} | ||
if !bytes.Equal(msg, got.Data) { | ||
t.Fatal("got wrong message!") | ||
} | ||
} | ||
|
||
// wait a bit to have some gossip interleaved | ||
time.Sleep(time.Millisecond * 100) | ||
} | ||
|
||
// and wait for some gossip flushing | ||
time.Sleep(time.Second * 2) | ||
} | ||
|
||
func TestGossipsubGossipPiggyback(t *testing.T) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to add some tests for Floodsub as well.