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

Support RHP4 #490

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
27 changes: 2 additions & 25 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"go.sia.tech/hostd/host/settings"
"go.sia.tech/hostd/host/settings/pin"
"go.sia.tech/hostd/host/storage"
"go.sia.tech/hostd/rhp"
"go.sia.tech/hostd/webhooks"
"go.sia.tech/jape"
"go.uber.org/zap"
Expand Down Expand Up @@ -86,7 +85,7 @@ type (
SetReadOnly(id int64, readOnly bool) error
RemoveSector(root types.Hash256) error
ResizeCache(size uint32)
Read(types.Hash256) (*[rhp2.SectorSize]byte, error)
ReadSector(types.Hash256) (*[rhp2.SectorSize]byte, error)

// SectorReferences returns the references to a sector
SectorReferences(root types.Hash256) (storage.SectorReference, error)
Expand Down Expand Up @@ -152,14 +151,6 @@ type (
BroadcastToWebhook(id int64, event, scope string, data interface{}) error
}

// A RHPSessionReporter reports on RHP session lifecycle events
RHPSessionReporter interface {
Subscribe(rhp.SessionSubscriber)
Unsubscribe(rhp.SessionSubscriber)

Active() []rhp.Session
}

// An api provides an HTTP API for the host
api struct {
hostKey types.PublicKey
Expand All @@ -168,7 +159,6 @@ type (
log *zap.Logger
alerts Alerts
webhooks Webhooks
sessions RHPSessionReporter

sqlite3Store SQLite3Store

Expand Down Expand Up @@ -201,22 +191,12 @@ func (a *api) requiresExplorer(h jape.Handler) jape.Handler {
}
}

// NewServer initializes the API
// syncer
// chain
// accounts
// contracts
// volumes
// wallet
// metrics
// settings
// index
// NewServer initializes the API server with the given options
func NewServer(name string, hostKey types.PublicKey, cm ChainManager, s Syncer, am AccountManager, c ContractManager, vm VolumeManager, wm Wallet, mm MetricManager, sm Settings, im Index, opts ...ServerOption) http.Handler {
a := &api{
hostKey: hostKey,
name: name,

sessions: noopSessionReporter{},
alerts: noopAlerts{},
webhooks: noopWebhooks{},
log: zap.NewNop(),
Expand Down Expand Up @@ -291,9 +271,6 @@ func NewServer(name string, hostKey types.PublicKey, cm ChainManager, s Syncer,
"DELETE /volumes/:id": a.handleDeleteVolume,
"DELETE /volumes/:id/cancel": a.handleDELETEVolumeCancelOp,
"PUT /volumes/:id/resize": a.handlePUTVolumeResize,
// session endpoints
"GET /sessions": a.handleGETSessions,
"GET /sessions/subscribe": a.handleGETSessionsSubscribe,
// tpool endpoints
"GET /tpool/fee": a.handleGETTPoolFee,
// wallet endpoints
Expand Down
14 changes: 0 additions & 14 deletions api/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"go.sia.tech/core/types"
"go.sia.tech/hostd/alerts"
"go.sia.tech/hostd/explorer"
"go.sia.tech/hostd/rhp"
"go.sia.tech/hostd/webhooks"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -51,13 +50,6 @@ func WithExplorer(explorer *explorer.Explorer) ServerOption {
}
}

// WithRHPSessionReporter sets the RHP session reporter for the API server.
func WithRHPSessionReporter(rsr RHPSessionReporter) ServerOption {
return func(a *api) {
a.sessions = rsr
}
}

// WithLogger sets the logger for the API server.
func WithLogger(log *zap.Logger) ServerOption {
return func(a *api) {
Expand All @@ -81,9 +73,3 @@ type noopAlerts struct{}

func (noopAlerts) Active() []alerts.Alert { return nil }
func (noopAlerts) Dismiss(...types.Hash256) {}

type noopSessionReporter struct{}

func (noopSessionReporter) Subscribe(rhp.SessionSubscriber) {}
func (noopSessionReporter) Unsubscribe(rhp.SessionSubscriber) {}
func (noopSessionReporter) Active() []rhp.Session { return nil }
21 changes: 0 additions & 21 deletions api/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,24 +462,3 @@ func (w WalletPendingResp) PrometheusMetric() (metrics []prometheus.Metric) {
}
return
}

// PrometheusMetric returns Prometheus samples for the hosts sessions
func (s SessionResp) PrometheusMetric() (metrics []prometheus.Metric) {
for _, session := range s {
metrics = append(metrics, prometheus.Metric{
Name: "hostd_session_ingress",
Labels: map[string]any{
"peer": session.PeerAddress,
},
Value: float64(session.Ingress),
})
metrics = append(metrics, prometheus.Metric{
Name: "hostd_session_egress",
Labels: map[string]any{
"peer": session.PeerAddress,
},
Value: float64(session.Egress),
})
}
return
}
45 changes: 0 additions & 45 deletions api/rhpsessions.go

This file was deleted.

4 changes: 0 additions & 4 deletions api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"go.sia.tech/hostd/host/metrics"
"go.sia.tech/hostd/host/settings"
"go.sia.tech/hostd/host/storage"
"go.sia.tech/hostd/rhp"
)

// JSON keys for host setting fields
Expand Down Expand Up @@ -193,9 +192,6 @@ type (

// WalletPendingResp is the response body for the [GET] /wallet/pending endpoint
WalletPendingResp []wallet.Event

// SessionResp is the response body for the [GET] /sessions endpoint
SessionResp []rhp.Session
)

// MarshalJSON implements json.Marshaler
Expand Down
4 changes: 2 additions & 2 deletions api/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,10 @@ func (a *api) handleGETVerifySector(jc jape.Context) {
}

// try to read the sector data and verify the root
data, err := a.volumes.Read(root)
sector, err := a.volumes.ReadSector(root)
if err != nil {
resp.Error = err.Error()
} else if calc := rhp2.SectorRoot(data); calc != root {
} else if calc := rhp2.SectorRoot(sector); calc != root {
resp.Error = fmt.Sprintf("sector is corrupt: expected root %q, got %q", root, calc)
}
jc.Encode(resp)
Expand Down
5 changes: 5 additions & 0 deletions cmd/hostd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ var (
RHP3: config.RHP3{
TCPAddress: ":9983",
},
RHP4: config.RHP4{
ListenAddresses: []config.RHP4ListenAddress{
{Protocol: "tcp", Address: ":9984"},
},
},
Log: config.Log{
Path: os.Getenv(logFileEnvVar), // deprecated. included for compatibility.
Level: "info",
Expand Down
Loading