-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: improve code layout and tests
- also remove the now extraneous subpackage readmes
- Loading branch information
Showing
43 changed files
with
361 additions
and
178 deletions.
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 was deleted.
Oops, something went wrong.
7 changes: 3 additions & 4 deletions
7
capabilities/pkg/assert/assert.go → capabilities/assert/assert.go
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
File renamed without changes.
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
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
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/ipfs/go-datastore" | ||
"github.com/ipfs/go-datastore/namespace" | ||
"github.com/ipld/go-ipld-prime" | ||
"github.com/libp2p/go-libp2p/core/crypto" | ||
"github.com/storacha/go-libstoracha/ipnipublisher/notifier" | ||
"github.com/storacha/go-libstoracha/ipnipublisher/publisher" | ||
"github.com/storacha/go-libstoracha/ipnipublisher/server" | ||
"github.com/storacha/go-libstoracha/ipnipublisher/store" | ||
) | ||
|
||
var ipniNamespace = datastore.NewKey("ipni/") | ||
var publisherNamespace = ipniNamespace.ChildString("publisher/") | ||
var notifierNamespace = ipniNamespace.ChildString("notifier/") | ||
|
||
func main() { | ||
ctx := context.Background() | ||
|
||
// generate a key pair | ||
priv, _, err := crypto.GenerateEd25519Key(nil) | ||
if err != nil { | ||
log.Fatalf("generating key pair: %s", err) | ||
} | ||
|
||
// setup datastore(s) | ||
ds := datastore.NewMapDatastore() | ||
publisherStore := store.FromDatastore(namespace.Wrap(ds, publisherNamespace)) | ||
|
||
// Setup publisher | ||
p, err := publisher.New( | ||
priv, | ||
publisherStore, | ||
publisher.WithDirectAnnounce("https://cid.contact/announce"), | ||
publisher.WithAnnounceAddrs("/dns4/localhost/tcp/3000/https"), | ||
) | ||
if err != nil { | ||
log.Fatalf("creating publisher: %s", err) | ||
} | ||
|
||
// Setup and start HTTP server (optional, but required if announce addresses configured). | ||
encodableStore, _ := publisherStore.(store.EncodeableStore) | ||
srv, err := server.NewServer(encodableStore, server.WithHTTPListenAddrs("localhost:3000")) | ||
if err != nil { | ||
log.Fatalf("creating server: %s", err) | ||
} | ||
if err := srv.Start(ctx); err != nil { | ||
log.Fatalf("starting server: %s", err) | ||
} | ||
defer func() { | ||
if err := srv.Shutdown(ctx); err != nil { | ||
log.Fatalf("shutting down server: %s", err) | ||
} | ||
}() | ||
|
||
// Setup remote sync notifications (optional). | ||
notifierStore := store.SimpleStoreFromDatastore(namespace.Wrap(ds, notifierNamespace)) | ||
notif, err := notifier.NewNotifierWithStorage("https://cid.contact/", priv, notifierStore) | ||
if err != nil { | ||
log.Fatalf("creating notifier: %s", err) | ||
} | ||
notif.Start(ctx) | ||
defer notif.Stop() | ||
|
||
notif.Notify(func(ctx context.Context, head, prev ipld.Link) { | ||
fmt.Printf("remote sync from %s to %s\n", prev, head) | ||
}) | ||
|
||
// Setup complete! Now publish an advert via the `Publish` method. | ||
// p.Publish(ctx, ...) | ||
|
||
fmt.Printf("Publisher: %+v\n", p) | ||
} |
File renamed without changes.
File renamed without changes.
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
Oops, something went wrong.