Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The following emojis are used to highlight certain changes:
### Changed

- Updated to [Go 1.25](https://go.dev/doc/go1.25)
- When `SOMEGUY_HTTP_BLOCK_PROVIDER_ENDPOINTS` are configured but no `SOMEGUY_HTTP_BLOCK_PROVIDER_PEERIDS` are configured, synthetic PeerIDs will now be autogenerated. These are deterministic placeholders derived from endpoint URLs, used only for routing system compatibility with HTTP-based trustless gateways - no libp2p cryptographic operations are performed with these IDs

### Removed

Expand Down
4 changes: 3 additions & 1 deletion docs/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ Default: none

### `SOMEGUY_HTTP_BLOCK_PROVIDER_PEERIDS`

Comma-separated list of [multibase-encoded peerIDs](https://github.com/libp2p/specs/blob/master/peer-ids/peer-ids.md#string-representation) to use in synthetic provider records returned for HTTP providers in `SOMEGUY_HTTP_BLOCK_PROVIDER_ENDPOINTS`.
Comma-separated list of [multibase-encoded peerIDs](https://github.com/libp2p/specs/blob/master/peer-ids/peer-ids.md#string-representation) to use in synthetic provider records returned for HTTP providers in `SOMEGUY_HTTP_BLOCK_PROVIDER_ENDPOINTS`. The order of PeerIDs must match the order of endpoints.

If no peerIDs are passed but provider endpoints are configured, synthetic PeerIDs will be automatically generated. These are deterministic identifiers derived from SHA256 hashes of the endpoint URLs, used solely for routing system compatibility. Since these providers use HTTP trustless gateway protocol rather than libp2p, the PeerIDs are purely synthetic and never participate in any cryptographic operations or peer authentication.

Default: none

Expand Down
23 changes: 23 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"crypto/sha256"
"errors"
"fmt"
"log"
Expand All @@ -12,6 +13,7 @@ import (
"github.com/ipfs/go-cid"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/multiformats/go-multibase"
"github.com/multiformats/go-multihash"
"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -175,6 +177,27 @@ func main() {
printIfListConfigured("SOMEGUY_PROVIDER_ENDPOINTS = ", cfg.contentEndpoints)
printIfListConfigured("SOMEGUY_PEER_ENDPOINTS = ", cfg.peerEndpoints)
printIfListConfigured("SOMEGUY_IPNS_ENDPOINTS = ", cfg.ipnsEndpoints)

if len(cfg.blockProviderEndpoints) > 0 && len(cfg.blockProviderPeerIDs) == 0 {
fmt.Printf("SOMEGUY_HTTP_BLOCK_PROVIDER_ENDPOINTS is set but SOMEGUY_HTTP_BLOCK_PROVIDER_PEERIDS were not. PeerIDs will be autogenerated.\n")
// Generate synthetic PeerIDs for HTTP block providers. These are deterministic
// identifiers based on endpoint URLs, used solely for routing system compatibility.
// Since HTTP providers use trustless gateway protocol, these PeerIDs are never
// used for cryptographic operations or libp2p authentication.
for i := 0; i < len(cfg.blockProviderEndpoints); i++ {
digest := sha256.Sum256([]byte(cfg.blockProviderEndpoints[i]))
mh, err := multihash.Encode((digest[:]), multihash.SHA2_256)
if err != nil {
return err
}
p, err := peer.IDFromBytes(mh)
if err != nil {
return err
}
cfg.blockProviderPeerIDs = append(cfg.blockProviderPeerIDs, p.String())
}
}

printIfListConfigured("SOMEGUY_HTTP_BLOCK_PROVIDER_ENDPOINTS = ", cfg.blockProviderEndpoints)
printIfListConfigured("SOMEGUY_HTTP_BLOCK_PROVIDER_PEERIDS = ", cfg.blockProviderPeerIDs)

Expand Down