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

Rename NetAddress to Transport #142

Merged
merged 2 commits into from Mar 1, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions rhp/v2/rhp.go
Expand Up @@ -75,6 +75,7 @@ type HostSettings struct {
MaxEphemeralAccountBalance types.Currency `json:"maxephemeralaccountbalance"`
RevisionNumber uint64 `json:"revisionnumber"`
Version string `json:"version"`
Release string `json:"release"`
SiaMuxPort string `json:"siamuxport"`
}

Expand Down Expand Up @@ -104,6 +105,7 @@ func (hs HostSettings) MarshalJSON() ([]byte, error) {
"maxephemeralaccountbalance": hs.MaxEphemeralAccountBalance,
"revisionnumber": hs.RevisionNumber,
"version": hs.Version,
"release": hs.Release,
"siamuxport": hs.SiaMuxPort,
})
}
Expand Down
22 changes: 12 additions & 10 deletions rhp/v4/encoding.go
Expand Up @@ -33,11 +33,12 @@ func (hp *HostPrices) DecodeFrom(d *types.Decoder) {

// EncodeTo implements types.EncoderTo.
func (hs HostSettings) EncodeTo(e *types.Encoder) {
e.Write(hs.Version[:])
e.WritePrefix(len(hs.NetAddresses))
for i := range hs.NetAddresses {
e.WriteString(hs.NetAddresses[i].Protocol)
e.WriteString(hs.NetAddresses[i].Address)
e.Write(hs.ProtocolVersion[:])
e.WriteString(hs.Release)
e.WritePrefix(len(hs.Transports))
for i := range hs.Transports {
e.WriteString(hs.Transports[i].Protocol)
e.WriteString(hs.Transports[i].Address)
}
hs.WalletAddress.EncodeTo(e)
e.WriteBool(hs.AcceptingContracts)
Expand All @@ -50,11 +51,12 @@ func (hs HostSettings) EncodeTo(e *types.Encoder) {

// DecodeFrom implements types.DecoderFrom.
func (hs *HostSettings) DecodeFrom(d *types.Decoder) {
d.Read(hs.Version[:])
hs.NetAddresses = make([]NetAddress, d.ReadPrefix())
for i := range hs.NetAddresses {
hs.NetAddresses[i].Protocol = d.ReadString()
hs.NetAddresses[i].Address = d.ReadString()
d.Read(hs.ProtocolVersion[:])
hs.Release = d.ReadString()
hs.Transports = make([]Transport, d.ReadPrefix())
for i := range hs.Transports {
hs.Transports[i].Protocol = d.ReadString()
hs.Transports[i].Address = d.ReadString()
}
hs.WalletAddress.DecodeFrom(d)
hs.AcceptingContracts = d.ReadBool()
Expand Down
9 changes: 5 additions & 4 deletions rhp/v4/rhp.go
Expand Up @@ -22,8 +22,8 @@ func round4KiB(n uint64) uint64 {
return (n + (1<<12 - 1)) &^ (1<<12 - 1)
}

// A NetAddress is a pair of protocol and address that a host may be reached on.
type NetAddress struct {
// A Transport is a pair of protocol and address that a host may be reached on.
type Transport struct {
Protocol string `json:"protocol"`
Address string `json:"address"`
}
Expand Down Expand Up @@ -53,8 +53,9 @@ func (hp HostPrices) WriteSectorCost(sector []byte) types.Currency {

// HostSettings specify the settings of a host.
type HostSettings struct {
Version [3]uint8 `json:"version"`
NetAddresses []NetAddress `json:"netAddresses"`
ProtocolVersion [3]uint8 `json:"protocolVersion"`
Release string `json:"release"`
Transports []Transport `json:"transports"`
WalletAddress types.Address `json:"walletAddress"`
AcceptingContracts bool `json:"acceptingContracts"`
MaxCollateral types.Currency `json:"maxCollateral"`
Expand Down