-
Notifications
You must be signed in to change notification settings - Fork 12
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
Add Persistence Layer on top of PubSub #33
Conversation
log.Debugf("PubsubResolve: subscribed to %s", key) | ||
|
||
if !bootstraped { |
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.
This section is blocked by libp2p/go-libp2p-pubsub#184
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.
Put bootstrapping logic back in to sidestep this for now
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.
Initial pass
pubsub.go
Outdated
return p.ps.Publish(topic, value) | ||
done := make(chan error, 1) | ||
go func() { | ||
done <- p.ps.Publish(topic, value) |
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.
Hm. Publish is really going to need to take a context: libp2p/go-libp2p-pubsub#184 (comment).
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.
Yes, removing all the bootstrapping code makes #28 really obvious. It also makes it easy to see that Publish
's lack of a context while potentially workable is quite problematic if we expect Publish
to be blocking after libp2p/go-libp2p-pubsub#184 lands.
… response can have nil data, use standard gogo protobuf tools). Changed the protocol string for the get-latest protocol. Separated out get-latest protocol and gave it explicit tests. Added more tests and modified an existing one to take into account the use of the get-latest protocol. Update go.mod to use newer (still forked) version of pubsub that has better peer event handling. Changed rebroadcast to use one goroutine instead of one per topic (also upped the rebroadcast interval). * Fixed existing issue with hanging on failed pubsub subscription. Better handling of contexts. Misc. code cleanup.
go-libp2p-pubsub-router/pubsub.go Lines 178 to 184 in 1b619f8
Can't reference this since I haven't changed it in this PR, but there's two potential oddities here.
Fine punting these (especially 2) until later if we want since it's potentially more complicated and I'm not sure if there are many consumers of |
Wrapped protocol read/writes in contexts. A little refactoring. Protobuf Makefile builds on Windows too.
cc8ab1c
to
f85f2bc
Compare
Without it I was running into issues where all my |
|
getlatest.go
Outdated
host host.Host | ||
} | ||
|
||
func newGetLatestProtocol(ctx context.Context, host host.Host, getLocal func(key string) ([]byte, error)) *getLatestProtocol { |
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.
We should probably make getLocal
part of the type, given its usage pattern.
Also, better to typedef the function type.
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.
typedef 👍 (or an interface would also be fine)
part of the type 👎
If you'd prefer passing in an interface we can do that, but there's no reason to tie this to any particular implementation of "get stuff". We use a data store for this in the rest of this library, but data store has put + get, and we only need get.
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.
it's better to be part of the type i think...
no need for an interface, just a function typedef will do.
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.
done, although we'll need to revisit this if/when we expose this function publicly since an interface will likely be more appropriate.
I'm rescinding this for now and will post something after testing. There needs to be some shenanigans around checking if we're using the win32 Edit: A patch can come in a later PR that fixes support for other versions of |
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.
LGTM modulo the protocol name and the replace directive. There's probably some cleanup we could do after all this refactoring but let's do that in a followup patch. This PR has >100 comments and >1000 lines.
pb "github.com/libp2p/go-libp2p-pubsub-router/pb" | ||
) | ||
|
||
const FetchProtoID = protocol.ID("/libp2p/fetch/0.0.1") |
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.
/libp2p/record-fetch/1
(or something). "fetch" is too generic (does it fetch blocks? keys? everything?). Users are going to try to use it to fetch IPLD blocks and be very confused.
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.
I guess I figured that it would just fetch anything (i.e. []byte
), and if for some reason someone wanted to configure their nodes to accept /ipfs/bafyABC
via fetch and return a block that's something that would be up to them to do. This would also make it easier for people to reuse this protocol within or on top of other protocols.
Is that too generic/confusing for people? Should we just restrict it to records (i.e. things with validators)?
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.
I actually really like this. +1
fetch.go
Outdated
} | ||
} | ||
|
||
func (p fetchProtocol) Get(ctx context.Context, pid peer.ID, key string) ([]byte, error) { |
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.
nit: inconsistent receiver.
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.
think this is fixed/better now. Just called it Fetch
.
pubsub.go
Outdated
return nil | ||
} | ||
|
||
func (p *PubsubValueStore) rebroadcast(ctx context.Context) { | ||
time.Sleep(p.rebroadcastInitialDelay) |
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.
nit for later: this should use a select and a time.After
.
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.
Done, although if we really wanted we might be able to up efficiency slightly by reusing a Timer instead of a ticker.
go.mod
Outdated
@@ -13,3 +14,5 @@ require ( | |||
github.com/libp2p/go-libp2p-routing-helpers v0.1.0 | |||
github.com/libp2p/go-libp2p-swarm v0.1.0 | |||
) | |||
|
|||
replace github.com/libp2p/go-libp2p-pubsub v0.1.0 => github.com/aschmahmann/go-libp2p-pubsub v0.0.4-0.20190807152749-d7996289bbcd |
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.
TODO
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.
Now uses a version of libp2p/pubsub from master. However, there hasn't been a release yet so it's referencing v0.1.1-0.20190807100218-9f04364996b4
…eiver instead of value.
This PR is essentially the other half of libp2p/go-libp2p-pubsub#190 which is meant to replace libp2p/go-libp2p-pubsub#171 as a means of having PubSub as an independent transport for a Best-Record-Wins Key-Value Store (ipfs/kubo#6447).
This also helps with libp2p/go-libp2p-pubsub#42, even though it is only a layer on-top of pubsub.
Brief summary from libp2p/go-libp2p-pubsub#190:
To have a persistence layer we need to:
Instead of doing this by making routers extensible, we will be leaving router extensibility for a later date and solve the issues above by:
This PR deals with 2 and 3.
Note this PR is blocked by libp2p/go-libp2p-pubsub#190 and to a lesser extent libp2p/go-libp2p-pubsub#184
@Stebalien @raulk @vyzo