本文整理匯總了Golang中github.com/NebulousLabs/Sia/modules.HostDBEntry.HostExternalSettings方法的典型用法代碼示例。如果您正苦於以下問題:Golang HostDBEntry.HostExternalSettings方法的具體用法?Golang HostDBEntry.HostExternalSettings怎麽用?Golang HostDBEntry.HostExternalSettings使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/NebulousLabs/Sia/modules.HostDBEntry
的用法示例。
在下文中一共展示了HostDBEntry.HostExternalSettings方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: verifySettings
// verifySettings reads a signed HostSettings object from conn, validates the
// signature, and checks for discrepancies between the known settings and the
// received settings. If there is a discrepancy, the hostDB is notified. The
// received settings are returned.
func verifySettings(conn net.Conn, host modules.HostDBEntry) (modules.HostDBEntry, error) {
// convert host key (types.SiaPublicKey) to a crypto.PublicKey
if host.PublicKey.Algorithm != types.SignatureEd25519 || len(host.PublicKey.Key) != crypto.PublicKeySize {
build.Critical("hostdb did not filter out host with wrong signature algorithm:", host.PublicKey.Algorithm)
return modules.HostDBEntry{}, errors.New("host used unsupported signature algorithm")
}
var pk crypto.PublicKey
copy(pk[:], host.PublicKey.Key)
// read signed host settings
var recvSettings modules.HostExternalSettings
if err := crypto.ReadSignedObject(conn, &recvSettings, modules.NegotiateMaxHostExternalSettingsLen, pk); err != nil {
return modules.HostDBEntry{}, errors.New("couldn't read host's settings: " + err.Error())
}
// TODO: check recvSettings against host.HostExternalSettings. If there is
// a discrepancy, write the error to conn.
if recvSettings.NetAddress != host.NetAddress {
// for now, just overwrite the NetAddress, since we know that
// host.NetAddress works (it was the one we dialed to get conn)
recvSettings.NetAddress = host.NetAddress
}
host.HostExternalSettings = recvSettings
return host, nil
}