-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
let starbase handle rebroadcast IPNS (#89)
* let starbase handle rebroadcast IPNS * move edit fx options to interface.go * fix golint * Update interface.go
- Loading branch information
Showing
3 changed files
with
152 additions
and
71 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 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,61 @@ | ||
package com | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/ipfs/kubo/core/node/helpers" | ||
libp2p "github.com/ipfs/kubo/core/node/libp2p" | ||
pubsub "github.com/libp2p/go-libp2p-pubsub" | ||
namesys "github.com/libp2p/go-libp2p-pubsub-router" | ||
record "github.com/libp2p/go-libp2p-record" | ||
routinghelpers "github.com/libp2p/go-libp2p-routing-helpers" | ||
"github.com/libp2p/go-libp2p/core/host" | ||
"go.uber.org/fx" | ||
) | ||
|
||
var ( | ||
neverDuration = 100 * 365 * 24 * time.Hour | ||
) | ||
|
||
type p2pPSRoutingIn struct { | ||
fx.In | ||
|
||
Validator record.Validator | ||
Host host.Host | ||
PubSub *pubsub.PubSub | ||
} | ||
|
||
type p2pRouterOut struct { | ||
fx.Out | ||
Router libp2p.Router `group:"routers"` | ||
} | ||
|
||
func PubsubRouter( | ||
mctx helpers.MetricsCtx, | ||
lc fx.Lifecycle, | ||
in p2pPSRoutingIn, | ||
) (p2pRouterOut, *namesys.PubsubValueStore, error) { | ||
psRouter, err := namesys.NewPubsubValueStore( | ||
helpers.LifecycleCtx(mctx, lc), | ||
in.Host, | ||
in.PubSub, | ||
in.Validator, | ||
namesys.WithRebroadcastInitialDelay(neverDuration), | ||
) | ||
|
||
if err != nil { | ||
return p2pRouterOut{}, nil, err | ||
} | ||
|
||
return p2pRouterOut{ | ||
Router: libp2p.Router{ | ||
Routing: &routinghelpers.Compose{ | ||
ValueStore: &routinghelpers.LimitedValueStore{ | ||
ValueStore: psRouter, | ||
Namespaces: []string{"ipns"}, | ||
}, | ||
}, | ||
Priority: 100, | ||
}, | ||
}, psRouter, nil | ||
} |
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 |
---|---|---|
|
@@ -30,73 +30,74 @@ import ( | |
// | ||
// Upgrade procedure (as of Kubo v1.9.0): | ||
// | ||
// 1. Clean up files in cmd/falcon/, keeping config/ and e2e/ directories. | ||
// cp -rf github.com/ipfs/kubo/cmd/ipfs/* cmd/falcon/ | ||
// | ||
// 2. Add falcon.ConfigOption() to daemonCmd.Options to receive falcon config | ||
// path from CLI flag. | ||
// | ||
// 3. Locate node creation code core.NewNode(...) in daemonFunc() from | ||
// cmd/falcon/daemon.go and add the following code before it: | ||
// | ||
// //////////////////// Falcon //////////////////// | ||
// if err := falcon.InitFalconBeforeNodeConstruction(req, repo); err != nil { | ||
// fmt.Printf("Error initializing falcon before IPFS node construction: %v", err) | ||
// return err | ||
// } | ||
// //////////////////// Falcon //////////////////// | ||
// | ||
// 4. Locate node creation code serveHTTPApi(...) in daemonFunc() from | ||
// cmd/falcon/daemon.go and add the following code before it: | ||
// | ||
// //////////////////// Falcon //////////////////// | ||
// falconErrc, err := falcon.InitFalconAfterNodeConstruction(req, cctx, node) | ||
// if err != nil { | ||
// fmt.Printf("Error initializing falcon after IPFS node construction: %v", err) | ||
// return err | ||
// } | ||
// //////////////////// Falcon //////////////////// | ||
// | ||
// 5. Update error channel merge loop to include falconErrc in daemonFunc() | ||
// from cmd/falcon/daemon.go: | ||
// | ||
// for err := range merge(apiErrc, gwErrc, gcErrc, falconErrc) { | ||
// ... | ||
// } | ||
// | ||
// 6. Disable default RPC API initialization in cmd/falcon/daemon.go by adding | ||
// the following code to the beginning of serveHTTPApi() from | ||
// from cmd/falcon/daemon.go: | ||
// | ||
// //////////////////// Falcon //////////////////// | ||
// if true { | ||
// return nil, nil | ||
// } | ||
// //////////////////// Falcon //////////////////// | ||
// | ||
// 7. Disable default gateway initialization in cmd/falcon/daemon.go by adding | ||
// the following code to the beginning of serveHTTPGateway() from | ||
// from cmd/falcon/daemon.go: | ||
// | ||
// //////////////////// Falcon //////////////////// | ||
// if true { | ||
// return nil, nil | ||
// } | ||
// //////////////////// Falcon //////////////////// | ||
// | ||
// 8. Disable debug handler in cmd/falcon/debug.go | ||
// | ||
// 9. Run `go mod tidy` to update go.mod with whats required by the new kubo | ||
// version. There might be a conflict with the otel package when building | ||
// falcon. Use `go get` to force the version used in kubo/go.mod. | ||
// For example: | ||
// go get go.opentelemetry.io/[email protected] | ||
// | ||
// 10. Make sure corenode.Core = fx.Options() assignments in | ||
// 1. Clean up files in cmd/falcon/, keeping config/ and e2e/ directories. | ||
// cp -rf github.com/ipfs/kubo/cmd/ipfs/* cmd/falcon/ | ||
// | ||
// 2. Add falcon.ConfigOption() to daemonCmd.Options to receive falcon config | ||
// path from CLI flag. | ||
// | ||
// 3. Locate node creation code core.NewNode(...) in daemonFunc() from | ||
// cmd/falcon/daemon.go and add the following code before it: | ||
// | ||
// //////////////////// Falcon //////////////////// | ||
// if err := falcon.InitFalconBeforeNodeConstruction(req, repo); err != nil { | ||
// fmt.Printf("Error initializing falcon before IPFS node construction: %v", err) | ||
// return err | ||
// } | ||
// //////////////////// Falcon //////////////////// | ||
// | ||
// 4. Locate node creation code serveHTTPApi(...) in daemonFunc() from | ||
// cmd/falcon/daemon.go and add the following code before it: | ||
// | ||
// //////////////////// Falcon //////////////////// | ||
// falconErrc, err := falcon.InitFalconAfterNodeConstruction(req, cctx, node) | ||
// if err != nil { | ||
// fmt.Printf("Error initializing falcon after IPFS node construction: %v", err) | ||
// return err | ||
// } | ||
// //////////////////// Falcon //////////////////// | ||
// | ||
// 5. Update error channel merge loop to include falconErrc in daemonFunc() | ||
// from cmd/falcon/daemon.go: | ||
// | ||
// for err := range merge(apiErrc, gwErrc, gcErrc, falconErrc) { | ||
// ... | ||
// } | ||
// | ||
// 6. Disable default RPC API initialization in cmd/falcon/daemon.go by adding | ||
// the following code to the beginning of serveHTTPApi() from | ||
// from cmd/falcon/daemon.go: | ||
// | ||
// //////////////////// Falcon //////////////////// | ||
// if true { | ||
// return nil, nil | ||
// } | ||
// //////////////////// Falcon //////////////////// | ||
// | ||
// 7. Disable default gateway initialization in cmd/falcon/daemon.go by adding | ||
// the following code to the beginning of serveHTTPGateway() from | ||
// from cmd/falcon/daemon.go: | ||
// | ||
// //////////////////// Falcon //////////////////// | ||
// if true { | ||
// return nil, nil | ||
// } | ||
// //////////////////// Falcon //////////////////// | ||
// | ||
// 8. Disable debug handler in cmd/falcon/debug.go | ||
// | ||
// 9. Run `go mod tidy` to update go.mod with whats required by the new kubo | ||
// version. There might be a conflict with the otel package when building | ||
// falcon. Use `go get` to force the version used in kubo/go.mod. | ||
// For example: | ||
// go get go.opentelemetry.io/[email protected] | ||
// | ||
// 10. Make sure corenode.Core = fx.Options() assignments in | ||
// InitFalconBeforeNodeConstruction is consistent with Kubo. | ||
// | ||
// Example command to run falcon daemon: | ||
// go run ./cmd/falcon/. daemon --falcon-config=./cmd/falcon/config/config_dev.yaml | ||
// | ||
// go run ./cmd/falcon/. daemon --falcon-config=./cmd/falcon/config/config_dev.yaml | ||
const ( | ||
falconConfigFile = "falcon-config" | ||
) | ||
|
@@ -148,6 +149,18 @@ func InitFalconBeforeNodeConstruction( | |
fx.Provide(corenode.Files), | ||
) | ||
|
||
cfg, err := rpo.Config() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if cfg.Ipns.UsePubsub.WithDefault(false) { | ||
// enable custom IPNS PubsubRouter | ||
corenode.IPNS = fx.Options( | ||
fx.Provide(corenode.RecordValidator), | ||
fx.Provide(com.PubsubRouter), | ||
) | ||
} | ||
return nil | ||
} | ||
|
||
|