Skip to content

Commit

Permalink
Merge pull request #195 from SiaFoundation/nate/auto-announce
Browse files Browse the repository at this point in the history
Automatically Announce
  • Loading branch information
n8maninger authored Nov 1, 2023
2 parents eeb000d + 0e9ad40 commit 6f338f1
Show file tree
Hide file tree
Showing 27 changed files with 542 additions and 71 deletions.
File renamed without changes.
3 changes: 2 additions & 1 deletion api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"go.sia.tech/core/consensus"
rhp3 "go.sia.tech/core/rhp/v3"
"go.sia.tech/core/types"
"go.sia.tech/hostd/alerts"
"go.sia.tech/hostd/host/accounts"
"go.sia.tech/hostd/host/alerts"
"go.sia.tech/hostd/host/contracts"
"go.sia.tech/hostd/host/metrics"
"go.sia.tech/hostd/host/settings"
Expand Down Expand Up @@ -39,6 +39,7 @@ type (

UpdateSettings(s settings.Settings) error
Settings() settings.Settings
LastAnnouncement() (settings.Announcement, error)

UpdateDDNS(force bool) error
}
Expand Down
15 changes: 11 additions & 4 deletions api/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,18 @@ func (a *api) checkServerError(c jape.Context, context string, err error) bool {
}

func (a *api) handleGETHostState(c jape.Context) {
announcement, err := a.settings.LastAnnouncement()
if err != nil {
c.Error(err, http.StatusInternalServerError)
return
}

c.Encode(HostState{
Name: a.name,
PublicKey: a.hostKey,
WalletAddress: a.wallet.Address(),
StartTime: startTime,
Name: a.name,
PublicKey: a.hostKey,
WalletAddress: a.wallet.Address(),
StartTime: startTime,
LastAnnouncement: announcement,
BuildState: BuildState{
Network: build.NetworkName(),
Version: build.Version(),
Expand Down
10 changes: 6 additions & 4 deletions api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"go.sia.tech/core/types"
"go.sia.tech/hostd/host/contracts"
"go.sia.tech/hostd/host/settings"
"go.sia.tech/hostd/host/storage"
)

Expand Down Expand Up @@ -50,10 +51,11 @@ type (

// HostState is the response body for the [GET] /state/host endpoint.
HostState struct {
Name string `json:"name,omitempty"`
PublicKey types.PublicKey `json:"publicKey"`
WalletAddress types.Address `json:"walletAddress"`
StartTime time.Time `json:"startTime"`
Name string `json:"name,omitempty"`
PublicKey types.PublicKey `json:"publicKey"`
LastAnnouncement settings.Announcement `json:"lastAnnouncement"`
WalletAddress types.Address `json:"walletAddress"`
StartTime time.Time `json:"startTime"`
BuildState
}

Expand Down
7 changes: 0 additions & 7 deletions cmd/hostd/metrics.go

This file was deleted.

7 changes: 4 additions & 3 deletions cmd/hostd/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"strings"

"go.sia.tech/core/types"
"go.sia.tech/hostd/alerts"
"go.sia.tech/hostd/host/accounts"
"go.sia.tech/hostd/host/alerts"
"go.sia.tech/hostd/host/contracts"
"go.sia.tech/hostd/host/metrics"
"go.sia.tech/hostd/host/registry"
Expand Down Expand Up @@ -162,13 +162,14 @@ func newNode(walletKey types.PrivateKey, logger *zap.Logger) (*node, types.Priva
discoveredAddr := net.JoinHostPort(g.Address().Host(), rhp2Port)
logger.Debug("discovered address", zap.String("addr", discoveredAddr))

sr, err := settings.NewConfigManager(cfg.Directory, hostKey, discoveredAddr, db, cm, tp, w, logger.Named("settings"))
am := alerts.NewManager()
sr, err := settings.NewConfigManager(cfg.Directory, hostKey, discoveredAddr, db, cm, tp, w, am, logger.Named("settings"))
if err != nil {
return nil, types.PrivateKey{}, fmt.Errorf("failed to create settings manager: %w", err)
}

accountManager := accounts.NewManager(db, sr)
am := alerts.NewManager()

sm, err := storage.NewVolumeManager(db, am, cm, logger.Named("volumes"), sr.Settings().SectorCacheSize)
if err != nil {
return nil, types.PrivateKey{}, fmt.Errorf("failed to create storage manager: %w", err)
Expand Down
36 changes: 36 additions & 0 deletions cmd/logparse/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main

import (
"encoding/json"
"os"
"strconv"
)

func main() {
f, err := os.Open("/Users/n8maninger/Downloads/hostd.log")
if err != nil {
panic(err)
}
defer f.Close()

dec := json.NewDecoder(f)

enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")

for {
var v map[string]any
if err := dec.Decode(&v); err != nil {
break
}

ts, _ := v["ts"].(string)
f, err := strconv.ParseFloat(ts, 64)
if err != nil {
continue
} else if f < 1693360589.0406103 {
continue
}
enc.Encode(v)
}
}
2 changes: 1 addition & 1 deletion host/accounts/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"time"

"go.sia.tech/core/types"
"go.sia.tech/hostd/alerts"
"go.sia.tech/hostd/host/accounts"
"go.sia.tech/hostd/host/alerts"
"go.sia.tech/hostd/host/contracts"
"go.sia.tech/hostd/host/settings"
"go.sia.tech/hostd/host/storage"
Expand Down
2 changes: 1 addition & 1 deletion host/accounts/budget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"time"

"go.sia.tech/core/types"
"go.sia.tech/hostd/alerts"
"go.sia.tech/hostd/host/accounts"
"go.sia.tech/hostd/host/alerts"
"go.sia.tech/hostd/host/contracts"
"go.sia.tech/hostd/host/storage"
"go.sia.tech/hostd/internal/chain"
Expand Down
2 changes: 1 addition & 1 deletion host/contracts/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

rhp2 "go.sia.tech/core/rhp/v2"
"go.sia.tech/core/types"
"go.sia.tech/hostd/host/alerts"
"go.sia.tech/hostd/alerts"
"go.uber.org/zap"
"lukechampine.com/frand"
)
Expand Down
2 changes: 1 addition & 1 deletion host/contracts/contracts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

rhp2 "go.sia.tech/core/rhp/v2"
"go.sia.tech/core/types"
"go.sia.tech/hostd/host/alerts"
"go.sia.tech/hostd/alerts"
"go.sia.tech/hostd/host/contracts"
"go.sia.tech/hostd/host/storage"
"go.sia.tech/hostd/internal/test"
Expand Down
2 changes: 1 addition & 1 deletion host/contracts/integrity.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

rhp2 "go.sia.tech/core/rhp/v2"
"go.sia.tech/core/types"
"go.sia.tech/hostd/host/alerts"
"go.sia.tech/hostd/alerts"
"go.uber.org/zap"
"lukechampine.com/frand"
)
Expand Down
2 changes: 1 addition & 1 deletion host/contracts/integrity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

rhp2 "go.sia.tech/core/rhp/v2"
"go.sia.tech/core/types"
"go.sia.tech/hostd/host/alerts"
"go.sia.tech/hostd/alerts"
"go.sia.tech/hostd/host/contracts"
"go.sia.tech/hostd/host/storage"
"go.sia.tech/hostd/internal/test"
Expand Down
2 changes: 1 addition & 1 deletion host/contracts/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"go.sia.tech/core/consensus"
rhp2 "go.sia.tech/core/rhp/v2"
"go.sia.tech/core/types"
"go.sia.tech/hostd/host/alerts"
"go.sia.tech/hostd/alerts"
"go.sia.tech/hostd/internal/chain"
"go.sia.tech/hostd/internal/threadgroup"
"go.sia.tech/siad/modules"
Expand Down
2 changes: 1 addition & 1 deletion host/contracts/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

rhp2 "go.sia.tech/core/rhp/v2"
"go.sia.tech/core/types"
"go.sia.tech/hostd/host/alerts"
"go.sia.tech/hostd/alerts"
"go.sia.tech/hostd/host/contracts"
"go.sia.tech/hostd/host/storage"
"go.sia.tech/hostd/internal/test"
Expand Down
Loading

0 comments on commit 6f338f1

Please sign in to comment.