reputation

package
v1.0.0-rc.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 29, 2024 License: Apache-2.0 Imports: 8 Imported by: 14

Documentation

Overview

Package reputation collects functionality related to the NeoFS reputation system.

The functionality is based on the system described in the NeoFS specification.

Trust type represents simple instances of trust values. PeerToPeerTrust extends Trust to support the direction of trust, i.e. from whom to whom. GlobalTrust is designed as a global measure of trust in a network member. See the docs for each type for details.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComparePeerKey

func ComparePeerKey(peer PeerID, key []byte) bool

ComparePeerKey checks if the given PeerID corresponds to the party authenticated by the given binary public key.

The key parameter is a slice of bytes is a serialized compressed public key. See [elliptic.MarshalCompressed].

Types

type GlobalTrust

type GlobalTrust struct {
	// contains filtered or unexported fields
}

GlobalTrust represents the final assessment of trust in the participant of the NeoFS reputation system obtained taking into account all other participants.

GlobalTrust is mutually compatible with github.com/nspcc-dev/neofs-api-go/v2/reputation.GlobalTrust message. See ReadFromV2 / WriteToV2 methods.

To submit GlobalTrust value in NeoFS zero instance SHOULD be declared, initialized using Init method and filled using dedicated methods.

Example (Marshalling)

Instances can be also used to process NeoFS API V2 protocol messages with [https://github.com/nspcc-dev/neofs-api] package.

package main

import (
	apiGoReputation "github.com/nspcc-dev/neofs-api-go/v2/reputation"
	"github.com/nspcc-dev/neofs-sdk-go/reputation"
)

func main() {
	// import apiGoReputation "github.com/nspcc-dev/neofs-api-go/v2/reputation"

	// On the client side.
	var trust reputation.GlobalTrust
	var msg apiGoReputation.GlobalTrust
	trust.WriteToV2(&msg)
	// *send message*

	// On the server side.
	_ = trust.ReadFromV2(msg)
}
Output:

func (*GlobalTrust) Init

func (x *GlobalTrust) Init()

Init initializes all internal data of the GlobalTrust required by NeoFS API protocol. Init MUST be called when creating a new global trust instance. Init SHOULD NOT be called multiple times. Init SHOULD NOT be called if the GlobalTrust instance is used for decoding only.

func (GlobalTrust) Manager

func (x GlobalTrust) Manager() (res PeerID)

Manager returns peer set using SetManager.

Zero GlobalTrust has zero manager which is incorrect according to the NeoFS API protocol.

func (GlobalTrust) Marshal

func (x GlobalTrust) Marshal() []byte

Marshal encodes GlobalTrust into a binary format of the NeoFS API protocol (Protocol Buffers with direct field order).

See also Unmarshal.

func (*GlobalTrust) ReadFromV2

func (x *GlobalTrust) ReadFromV2(m reputation.GlobalTrust) error

ReadFromV2 reads GlobalTrust from the reputation.GlobalTrust message. Returns an error if the message is malformed according to the NeoFS API V2 protocol.

See also WriteToV2.

func (*GlobalTrust) SetManager

func (x *GlobalTrust) SetManager(id PeerID)

SetManager sets identifier of the NeoFS reputation system's participant which performed trust estimation.

See also Manager.

func (*GlobalTrust) SetTrust

func (x *GlobalTrust) SetTrust(trust Trust)

SetTrust sets the global trust score of the network to a specific network member.

See also Trust.

func (*GlobalTrust) Sign

func (x *GlobalTrust) Sign(signer neofscrypto.Signer) error

Sign calculates and writes signature of the GlobalTrust data. Returns signature calculation errors.

Zero GlobalTrust is unsigned.

Note that any GlobalTrust mutation is likely to break the signature, so it is expected to be calculated as a final stage of GlobalTrust formation.

See also GlobalTrust.VerifySignature, GlobalTrust.SignedData.

func (*GlobalTrust) SignedData

func (x *GlobalTrust) SignedData() []byte

SignedData returns actual payload to sign.

See also GlobalTrust.Sign.

func (GlobalTrust) Trust

func (x GlobalTrust) Trust() (res Trust)

Trust returns trust set using SetTrust.

Zero GlobalTrust return zero Trust which is incorrect according to the NeoFS API protocol.

func (*GlobalTrust) Unmarshal

func (x *GlobalTrust) Unmarshal(data []byte) error

Unmarshal decodes NeoFS API protocol binary format into the GlobalTrust (Protocol Buffers with direct field order). Returns an error describing a format violation.

See also Marshal.

func (GlobalTrust) VerifySignature

func (x GlobalTrust) VerifySignature() bool

VerifySignature checks if GlobalTrust signature is presented and valid.

Zero GlobalTrust fails the check.

See also Sign.

func (GlobalTrust) WriteToV2

func (x GlobalTrust) WriteToV2(m *reputation.GlobalTrust)

WriteToV2 writes GlobalTrust to the reputation.GlobalTrust message. The message must not be nil.

See also ReadFromV2.

type PeerID

type PeerID struct {
	// contains filtered or unexported fields
}

PeerID represents unique identifier of the peer participating in the NeoFS reputation system.

ID is mutually compatible with github.com/nspcc-dev/neofs-api-go/v2/reputation.PeerID message. See ReadFromV2 / WriteToV2 methods.

Instances can be created using built-in var declaration.

func (*PeerID) DecodeString

func (x *PeerID) DecodeString(s string) error

DecodeString decodes string into PeerID according to NeoFS API protocol. Returns an error if s is malformed.

See also DecodeString.

func (PeerID) EncodeToString

func (x PeerID) EncodeToString() string

EncodeToString encodes ID into NeoFS API protocol string.

Zero PeerID is base58 encoding of PeerIDSize zeros.

See also DecodeString.

func (PeerID) PublicKey

func (x PeerID) PublicKey() []byte

PublicKey return public key set using PeerID.SetPublicKey.

Zero PeerID has zero key which is incorrect according to NeoFS API protocol.

The resulting slice of bytes is a serialized compressed public key. See [elliptic.MarshalCompressed]. Use [neofsecdsa.PublicKey.Decode] to decode it into a type-specific structure.

The value returned shares memory with the structure itself, so changing it can lead to data corruption. Make a copy if you need to change it.

func (*PeerID) ReadFromV2

func (x *PeerID) ReadFromV2(m reputation.PeerID) error

ReadFromV2 reads PeerID from the reputation.PeerID message. Returns an error if the message is malformed according to the NeoFS API V2 protocol.

See also WriteToV2.

func (*PeerID) SetPublicKey

func (x *PeerID) SetPublicKey(key []byte)

SetPublicKey sets PeerID as a binary-encoded public key which authenticates the participant of the NeoFS reputation system.

Argument MUST NOT be mutated, make a copy first.

Parameter key is a serialized compressed public key. See [elliptic.MarshalCompressed].

See also ComparePeerKey.

func (PeerID) String

func (x PeerID) String() string

String implements fmt.Stringer.

String is designed to be human-readable, and its format MAY differ between SDK versions. String MAY return same result as EncodeToString. String MUST NOT be used to encode ID into NeoFS protocol string.

func (PeerID) WriteToV2

func (x PeerID) WriteToV2(m *reputation.PeerID)

WriteToV2 writes PeerID to the reputation.PeerID message. The message must not be nil.

See also ReadFromV2.

type PeerToPeerTrust

type PeerToPeerTrust struct {
	// contains filtered or unexported fields
}

PeerToPeerTrust represents trust of one participant of the NeoFS reputation system to another one.

Trust is mutually compatible with github.com/nspcc-dev/neofs-api-go/v2/reputation.PeerToPeerTrust message. See ReadFromV2 / WriteToV2 methods.

Instances can be created using built-in var declaration.

func (*PeerToPeerTrust) ReadFromV2

ReadFromV2 reads PeerToPeerTrust from the reputation.PeerToPeerTrust message. Returns an error if the message is malformed according to the NeoFS API V2 protocol.

See also WriteToV2.

func (*PeerToPeerTrust) SetTrust

func (x *PeerToPeerTrust) SetTrust(t Trust)

SetTrust sets trust value of the trusting peer to another participant of the NeoFS reputation system.

See also Trust.

func (*PeerToPeerTrust) SetTrustingPeer

func (x *PeerToPeerTrust) SetTrustingPeer(id PeerID)

SetTrustingPeer specifies the peer from which trust comes in terms of the NeoFS reputation system.

See also TrustingPeer.

func (PeerToPeerTrust) Trust

func (x PeerToPeerTrust) Trust() (res Trust)

Trust returns trust set using SetTrust.

Zero PeerToPeerTrust returns zero Trust which is incorect according to the NeoFS API protocol.

func (PeerToPeerTrust) TrustingPeer

func (x PeerToPeerTrust) TrustingPeer() (res PeerID)

TrustingPeer returns peer set using SetTrustingPeer.

Zero PeerToPeerTrust has no trusting peer which is incorrect according to the NeoFS API protocol.

func (PeerToPeerTrust) WriteToV2

func (x PeerToPeerTrust) WriteToV2(m *reputation.PeerToPeerTrust)

WriteToV2 writes PeerToPeerTrust to the reputation.PeerToPeerTrust message. The message must not be nil.

See also ReadFromV2.

type Trust

type Trust struct {
	// contains filtered or unexported fields
}

Trust represents quantitative assessment of the trust of a participant in the NeoFS reputation system.

Trust is mutually compatible with github.com/nspcc-dev/neofs-api-go/v2/reputation.Trust message. See ReadFromV2 / WriteToV2 methods.

Instances can be created using built-in var declaration.

func (Trust) Peer

func (x Trust) Peer() (res PeerID)

Peer returns peer identifier set using SetPeer.

Zero Trust returns zero PeerID which is incorrect according to the NeoFS API protocol.

func (*Trust) ReadFromV2

func (x *Trust) ReadFromV2(m reputation.Trust) error

ReadFromV2 reads Trust from the reputation.Trust message. Returns an error if the message is malformed according to the NeoFS API V2 protocol.

See also WriteToV2.

func (*Trust) SetPeer

func (x *Trust) SetPeer(id PeerID)

SetPeer specifies identifier of the participant of the NeoFS reputation system to which the Trust relates.

See also Peer.

func (*Trust) SetValue

func (x *Trust) SetValue(val float64)

SetValue sets the Trust value. Value MUST be in range [0;1].

See also Value.

func (Trust) Value

func (x Trust) Value() float64

Value returns value set using SetValue.

Zero Trust has zero value.

func (Trust) WriteToV2

func (x Trust) WriteToV2(m *reputation.Trust)

WriteToV2 writes Trust to the reputation.Trust message. The message must not be nil.

See also ReadFromV2.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL