Skip to content
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

renames + better logging around republishing #191

Merged
merged 8 commits into from
Apr 19, 2024
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
28 changes: 28 additions & 0 deletions .github/workflows/dependabot-auto.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Dependabot auto-approve and merge
on: pull_request

permissions:
contents: write
pull-requests: write

jobs:
approve:
runs-on: ubuntu-latest
if: github.actor == 'dependabot[bot]'
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v2
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- name: Approve a PR
run: gh pr review --approve "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Enable auto-merge for Dependabot PRs
if: contains(steps.metadata.outputs.dependency-names, 'my-dependency') && steps.metadata.outputs.update-type == 'version-update:semver-patch'
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
4 changes: 2 additions & 2 deletions impl/cmd/cli/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ var identityAddCmd = &cobra.Command{
Answer: rrds,
}
// generate put request
putReq, err := dht.CreatePkarrPublishRequest(privKey, msg)
putReq, err := dht.CreateDNSPublishRequest(privKey, msg)
if err != nil {
logrus.WithError(err).Error("failed to create put request")
return err
Expand Down Expand Up @@ -170,7 +170,7 @@ var identityGetCmd = &cobra.Command{
return err
}

msg, err := dht.ParsePkarrGetResponse(*gotResp)
msg, err := dht.ParseDNSGetResponse(*gotResp)
if err != nil {
logrus.WithError(err).Error("failed to parse get response")
return err
Expand Down
2 changes: 1 addition & 1 deletion impl/concurrencytest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func generateDIDPutRequest() (string, []byte, error) {
return "", nil, err
}

bep44Put, err := dht.CreatePkarrPublishRequest(sk, *packet)
bep44Put, err := dht.CreateDNSPublishRequest(sk, *packet)
if err != nil {
return "", nil, err
}
Expand Down
22 changes: 8 additions & 14 deletions impl/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ func (e EnvironmentVariable) String() string {
}

type Config struct {
Log LogConfig `toml:"log"`
ServerConfig ServerConfig `toml:"server"`
DHTConfig DHTServiceConfig `toml:"dht"`
PkarrConfig PkarrServiceConfig `toml:"pkarr"`
Log LogConfig `toml:"log"`
ServerConfig ServerConfig `toml:"server"`
DHTConfig DHTServiceConfig `toml:"dht"`
}

type ServerConfig struct {
Expand All @@ -57,13 +56,10 @@ type ServerConfig struct {
}

type DHTServiceConfig struct {
BootstrapPeers []string `toml:"bootstrap_peers"`
}

type PkarrServiceConfig struct {
RepublishCRON string `toml:"republish_cron"`
CacheTTLSeconds int `toml:"cache_ttl_seconds"`
CacheSizeLimitMB int `toml:"cache_size_limit_mb"`
BootstrapPeers []string `toml:"bootstrap_peers"`
RepublishCRON string `toml:"republish_cron"`
CacheTTLSeconds int `toml:"cache_ttl_seconds"`
CacheSizeLimitMB int `toml:"cache_size_limit_mb"`
}

type LogConfig struct {
Expand All @@ -81,9 +77,7 @@ func GetDefaultConfig() Config {
Telemetry: false,
},
DHTConfig: DHTServiceConfig{
BootstrapPeers: GetDefaultBootstrapPeers(),
},
PkarrConfig: PkarrServiceConfig{
BootstrapPeers: GetDefaultBootstrapPeers(),
RepublishCRON: "0 */3 * * *",
CacheTTLSeconds: 600,
CacheSizeLimitMB: 1000,
Expand Down
2 changes: 0 additions & 2 deletions impl/config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ telemetry = false
[dht]
bootstrap_peers = ["router.magnets.im:6881", "router.bittorrent.com:6881", "dht.transmissionbt.com:6881",
"router.utorrent.com:6881", "router.nuh.dev:6881"]

[pkarr]
republish_cron = "0 */3 * * *" # every 3 hours
cache_ttl_seconds = 600 # 10 minutes
cache_size_limit_mb = 1000 # 1000 MB
12 changes: 6 additions & 6 deletions impl/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ paths:
get:
consumes:
- application/octet-stream
description: GetRecord a Pkarr record from the DHT
description: GetRecord a BEP44 DNS record from the DHT
parameters:
- description: ID to get
in: path
Expand Down Expand Up @@ -48,13 +48,13 @@ paths:
description: Internal server error
schema:
type: string
summary: GetRecord a Pkarr record from the DHT
summary: GetRecord a BEP44 DNS record from the DHT
tags:
- Pkarr
- DHT
put:
consumes:
- application/octet-stream
description: PutRecord a Pkarr record into the DHT
description: PutRecord a BEP44 DNS record into the DHT
parameters:
- description: ID of the record to put
in: path
Expand All @@ -80,9 +80,9 @@ paths:
description: Internal server error
schema:
type: string
summary: PutRecord a Pkarr record into the DHT
summary: PutRecord a BEP44 DNS record into the DHT
tags:
- Pkarr
- DHT
/health:
get:
consumes:
Expand Down
2 changes: 1 addition & 1 deletion impl/integrationtest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func generateDIDPutRequest() (string, []byte, error) {
return "", nil, err
}

bep44Put, err := dht.CreatePkarrPublishRequest(sk, *packet)
bep44Put, err := dht.CreateDNSPublishRequest(sk, *packet)
if err != nil {
return "", nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion impl/internal/did/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestClient(t *testing.T) {
assert.NoError(t, err)
assert.NotEmpty(t, packet)

bep44Put, err := dht.CreatePkarrPublishRequest(sk, *packet)
bep44Put, err := dht.CreateDNSPublishRequest(sk, *packet)
assert.NoError(t, err)
assert.NotEmpty(t, bep44Put)

Expand Down
2 changes: 1 addition & 1 deletion impl/internal/did/did.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func (d DHT) ToDNSPacket(doc did.Document, types []TypeIndex, gateways []Authori

keyType := keyTypeForJWK(*vm.PublicKeyJWK)
if keyType < 0 {
return nil, fmt.Errorf("+unsupported key type given alg: %s", vm.PublicKeyJWK.ALG)
return nil, fmt.Errorf("unsupported key type given alg: %s", vm.PublicKeyJWK.ALG)
}

// convert the public key to a base64url encoded string
Expand Down
14 changes: 7 additions & 7 deletions impl/pkg/dht/pkarr.go → impl/pkg/dht/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import (
"github.com/TBD54566975/did-dht-method/internal/dht"
)

// CreatePkarrPublishRequest creates a put request for the given records. Requires a public/private keypair and the records to put.
// The records are expected to be a DNS message packet, such as:
// CreateDNSPublishRequest creates a put request for the given records. Requires a public/private keypair and
// the records to put. The records are expected to be a DNS message packet, such as:
//
// dns.Msg{
// MsgHdr: dns.MsgHdr{
// Id: 0,
// Response: true,
// BEP44Response: true,
// Authoritative: true,
// },
// Answer: dns.RR{
Expand All @@ -30,11 +30,11 @@ import (
// Ttl: 7200,
// },
// Txt: []string{
// "hello pkarr",
// "hello mainline",
// },
// }
// }
func CreatePkarrPublishRequest(privateKey ed25519.PrivateKey, msg dns.Msg) (*bep44.Put, error) {
func CreateDNSPublishRequest(privateKey ed25519.PrivateKey, msg dns.Msg) (*bep44.Put, error) {
packed, err := msg.Pack()
if err != nil {
return nil, util.LoggingErrorMsg(err, "failed to pack records")
Expand All @@ -49,9 +49,9 @@ func CreatePkarrPublishRequest(privateKey ed25519.PrivateKey, msg dns.Msg) (*bep
return put, nil
}

// ParsePkarrGetResponse parses the response from a get request.
// ParseDNSGetResponse parses the response from a get request.
// The response is expected to be a slice of DNS resource records.
func ParsePkarrGetResponse(response dht.FullGetResult) (*dns.Msg, error) {
func ParseDNSGetResponse(response dht.FullGetResult) (*dns.Msg, error) {
var payload string
if err := bencode.Unmarshal(response.V, &payload); err != nil {
return nil, util.LoggingErrorMsg(err, "failed to unmarshal payload value")
Expand Down
12 changes: 6 additions & 6 deletions impl/pkg/dht/pkarr_test.go → impl/pkg/dht/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/TBD54566975/did-dht-method/internal/util"
)

func TestGetPutPkarrDHT(t *testing.T) {
func TestGetPutDNSDHT(t *testing.T) {
dht := NewTestDHT(t)
defer dht.Close()

Expand All @@ -31,7 +31,7 @@ func TestGetPutPkarrDHT(t *testing.T) {
Ttl: 7200,
},
Txt: []string{
"hello pkarr",
"hello mainline",
},
}
msg := dns.Msg{
Expand All @@ -42,7 +42,7 @@ func TestGetPutPkarrDHT(t *testing.T) {
},
Answer: []dns.RR{&txtRecord},
}
put, err := CreatePkarrPublishRequest(privKey, msg)
put, err := CreateDNSPublishRequest(privKey, msg)
require.NoError(t, err)

id, err := dht.Put(context.Background(), *put)
Expand All @@ -53,7 +53,7 @@ func TestGetPutPkarrDHT(t *testing.T) {
require.NoError(t, err)
require.NotEmpty(t, got)

gotMsg, err := ParsePkarrGetResponse(*got)
gotMsg, err := ParseDNSGetResponse(*got)
require.NoError(t, err)
require.NotEmpty(t, gotMsg.Answer)

Expand Down Expand Up @@ -103,7 +103,7 @@ func TestGetPutDIDDHT(t *testing.T) {
didDocPacket, err := didID.ToDNSPacket(*doc, nil, nil)
require.NoError(t, err)

putReq, err := CreatePkarrPublishRequest(privKey, *didDocPacket)
putReq, err := CreateDNSPublishRequest(privKey, *didDocPacket)
require.NoError(t, err)

gotID, err := dht.Put(context.Background(), *putReq)
Expand All @@ -114,7 +114,7 @@ func TestGetPutDIDDHT(t *testing.T) {
require.NoError(t, err)
require.NotEmpty(t, got)

gotMsg, err := ParsePkarrGetResponse(*got)
gotMsg, err := ParseDNSGetResponse(*got)
require.NoError(t, err)
require.NotEmpty(t, gotMsg.Answer)

Expand Down
Loading
Loading