-
Wolfgang Welz authored
*
GetNextCandidate selection added * Recompile salt.proto * Refactor peer IDs completely * Recompile proto sources * WIP * renamed to sort * Return requested peers on request * Kepp track how ofter a managed peer was verified * sort adapted to the new peer * Query verified peers for new peers * WIP * Add manager tests * Add peering messages to protobuf * Make Salt methods consistent with Peer * Handle peering messages * WIP * Add To filed to PeersRequest * Add PeersRequest test * Adding PeersRequest benchmark * Move mpeer and helper functions to own file * Bump peer only once on reverification * WIP * * WIP * Increase buffer to prevent deadlocks * Remove unnecessary lock * Add peering request test * Make tests deterministic by triggering reverify * WIP * fixing concurrency issues * testManager improved * Don't send PeeringResponse for invalid salt * WIP * WIP * removed commented code * WIP * WIP * Neighbourhood manager (#11) * GetNextCandidate selection added * fixing concurrency issues * testManager improved * removed commented code * WIP * WIP * WIP * WIP * Make TestAdd pass in neighborhood_test `Add` should do nothing if the neighborhood list is full. * Improve TestSrvVerifyBoot * Upgrade to go 1.13 * Use testify instead of magiconair/properties * * WIP * WIP * WIP * WIP * Simulation (#14) * clear rejection filter after refreshing the public salt * clean rejection filter * Add mpeer test * gofmt test * Remove ineffactual assignments * Trigger panic when index is out of bound in deletePeer * Add selection test * Add TestGetFurtherest and TestGetPeerIndex * both salt updated at the same time and neighborhood dropped * Add node peering history for simulation * WIP * added sim visualization * removed root handler * added README * updated README * removed unused dependencies * Tidy go.mod * Work in progress * WIP * WIP * WIP * improved start button * WIP * added keyboard support for start * WIP * WIP * WIP * WIP * WIP * WIP * added input parameters * README updated * gif updated * figure updated * updated * updated gif * removed simulation metrics * updated * updated * Extract server from discovery and peering * Use golang/protobuf * Update README.md * Rename PeersRequest to DiscoveryRequest * Fixing typos * Move unused function to tests * The selection protocol depends on the discovery * Make tests more robust when using -race * Improve logging * Remove unnecessary arguments * Fix data races * added timeout for simulated network * added loop to animation * rename neighborhood to selection * adds initial salt and fixes simulation end * visualizer enabled by default * new parameter dropAll and improved python script * updated README * updated README * fix salt initialization * added blogpost link * Add badges to README * Add Travis CI for tests * Correct formating * Running golangci on Travis * Ignore return value of 'logger.Sync' * Remove unused functions * Add link to license * Move simnetwork to transport * Use the complete network protocol in simulations * Do not export selection/manager * Remove gRPC transport layer * Add UDP connection transport test * Implement the peer DB using Goshimmer database * Use the local GoShimmer version * Add support for a persistent database * Persist private key of local peer in database * Set TTL for bootstrap peers * Use GoShimmer events * Store the supported services in the local peer * Use most current GoShimmer git version as a dep * Switch to hive.go event package * Use correct module iotaledger/autopeering-sim * Provide dummy service in autopeering simulation * adds service support in the selection * adds peer discovered events * adds GetIncomingNeighbors and GetOutgoingNeighbors * fixes out of bound error in splitNodeKey * adds public IP support * fixes localhost * fixes localhost parsing * changes selection loop to 1s * switches from fmt.Println to log.Debug * increases maxKnown to 1000 and always triggers discovered peer * adds PeerDeleted event * moves PeerDeleted event into deletePeer * adds config paramters for the peer discovery * adds config parameters to neighbor selection * enable/disable inbound/outbound selection * Improve Godoc comments * modifies disabled outbound selection * fixes bug with disabling the selection * removes getMyIP() from server * removes some debugging logs * Introduce services - Each peer now comes with a set of services - Local peer is a proper peer - Services are exchanged during Pong and are available for all verified peers * fixes GetVerifiedPeer * adds gossip key to the service * removes debugging logs * Add test for GetVerifiedPeer * Fix main * Add localNetwork to Protocol * Add new but verified peers to the manager * changes configurable parameters * fixes DiscoveryRequest field sequence * Regenerate proto files * Cleanup parameters * Fix potential race condition * Reduce logging verbosity * Add test for selection+discover * Return net.Addr in Transport * Remove inbound/outbound switches completely * Improve logging * Fix peerdb logs * Fix peer updating * Make TestProtFull more robust * Make queryInterval a parameter * Improve loggind during querying * Trigger PeerDiscovered only for active peers * Cleanup protocol tests * Add discovery test on protocol level * Rename maxVerified to maxManaged * Increase default query interval * Improve discover benchmarks * Fix manager tests * Do not use bugged assert.Eventually * Fix linter warnings in server * Remove unused parameters * Make transport work on slices of bytes * Fix typo in comments * Fix linter warnings * UpdateService accepts two strings * Add test that services are received in discover * adds required services * Handle closed connections consistently * Code cleanup * fixes DropPeer * improves debug messages * Log errors during reverification * Log packet size * refactor: remove unused files * refactor: use internal autopeering package Co-authored-by:Angelo Capossele <angelocapossele@gmail.com> Co-authored-by:
jkrvivian <jkrvivian@gmail.com>
Wolfgang Welz authored*
GetNextCandidate selection added * Recompile salt.proto * Refactor peer IDs completely * Recompile proto sources * WIP * renamed to sort * Return requested peers on request * Kepp track how ofter a managed peer was verified * sort adapted to the new peer * Query verified peers for new peers * WIP * Add manager tests * Add peering messages to protobuf * Make Salt methods consistent with Peer * Handle peering messages * WIP * Add To filed to PeersRequest * Add PeersRequest test * Adding PeersRequest benchmark * Move mpeer and helper functions to own file * Bump peer only once on reverification * WIP * * WIP * Increase buffer to prevent deadlocks * Remove unnecessary lock * Add peering request test * Make tests deterministic by triggering reverify * WIP * fixing concurrency issues * testManager improved * Don't send PeeringResponse for invalid salt * WIP * WIP * removed commented code * WIP * WIP * Neighbourhood manager (#11) * GetNextCandidate selection added * fixing concurrency issues * testManager improved * removed commented code * WIP * WIP * WIP * WIP * Make TestAdd pass in neighborhood_test `Add` should do nothing if the neighborhood list is full. * Improve TestSrvVerifyBoot * Upgrade to go 1.13 * Use testify instead of magiconair/properties * * WIP * WIP * WIP * WIP * Simulation (#14) * clear rejection filter after refreshing the public salt * clean rejection filter * Add mpeer test * gofmt test * Remove ineffactual assignments * Trigger panic when index is out of bound in deletePeer * Add selection test * Add TestGetFurtherest and TestGetPeerIndex * both salt updated at the same time and neighborhood dropped * Add node peering history for simulation * WIP * added sim visualization * removed root handler * added README * updated README * removed unused dependencies * Tidy go.mod * Work in progress * WIP * WIP * WIP * improved start button * WIP * added keyboard support for start * WIP * WIP * WIP * WIP * WIP * WIP * added input parameters * README updated * gif updated * figure updated * updated * updated gif * removed simulation metrics * updated * updated * Extract server from discovery and peering * Use golang/protobuf * Update README.md * Rename PeersRequest to DiscoveryRequest * Fixing typos * Move unused function to tests * The selection protocol depends on the discovery * Make tests more robust when using -race * Improve logging * Remove unnecessary arguments * Fix data races * added timeout for simulated network * added loop to animation * rename neighborhood to selection * adds initial salt and fixes simulation end * visualizer enabled by default * new parameter dropAll and improved python script * updated README * updated README * fix salt initialization * added blogpost link * Add badges to README * Add Travis CI for tests * Correct formating * Running golangci on Travis * Ignore return value of 'logger.Sync' * Remove unused functions * Add link to license * Move simnetwork to transport * Use the complete network protocol in simulations * Do not export selection/manager * Remove gRPC transport layer * Add UDP connection transport test * Implement the peer DB using Goshimmer database * Use the local GoShimmer version * Add support for a persistent database * Persist private key of local peer in database * Set TTL for bootstrap peers * Use GoShimmer events * Store the supported services in the local peer * Use most current GoShimmer git version as a dep * Switch to hive.go event package * Use correct module iotaledger/autopeering-sim * Provide dummy service in autopeering simulation * adds service support in the selection * adds peer discovered events * adds GetIncomingNeighbors and GetOutgoingNeighbors * fixes out of bound error in splitNodeKey * adds public IP support * fixes localhost * fixes localhost parsing * changes selection loop to 1s * switches from fmt.Println to log.Debug * increases maxKnown to 1000 and always triggers discovered peer * adds PeerDeleted event * moves PeerDeleted event into deletePeer * adds config paramters for the peer discovery * adds config parameters to neighbor selection * enable/disable inbound/outbound selection * Improve Godoc comments * modifies disabled outbound selection * fixes bug with disabling the selection * removes getMyIP() from server * removes some debugging logs * Introduce services - Each peer now comes with a set of services - Local peer is a proper peer - Services are exchanged during Pong and are available for all verified peers * fixes GetVerifiedPeer * adds gossip key to the service * removes debugging logs * Add test for GetVerifiedPeer * Fix main * Add localNetwork to Protocol * Add new but verified peers to the manager * changes configurable parameters * fixes DiscoveryRequest field sequence * Regenerate proto files * Cleanup parameters * Fix potential race condition * Reduce logging verbosity * Add test for selection+discover * Return net.Addr in Transport * Remove inbound/outbound switches completely * Improve logging * Fix peerdb logs * Fix peer updating * Make TestProtFull more robust * Make queryInterval a parameter * Improve loggind during querying * Trigger PeerDiscovered only for active peers * Cleanup protocol tests * Add discovery test on protocol level * Rename maxVerified to maxManaged * Increase default query interval * Improve discover benchmarks * Fix manager tests * Do not use bugged assert.Eventually * Fix linter warnings in server * Remove unused parameters * Make transport work on slices of bytes * Fix typo in comments * Fix linter warnings * UpdateService accepts two strings * Add test that services are received in discover * adds required services * Handle closed connections consistently * Code cleanup * fixes DropPeer * improves debug messages * Log errors during reverification * Log packet size * refactor: remove unused files * refactor: use internal autopeering package Co-authored-by:Angelo Capossele <angelocapossele@gmail.com> Co-authored-by:
jkrvivian <jkrvivian@gmail.com>
salt.go 2.05 KiB
package salt
import (
"crypto/rand"
"fmt"
"sync"
"time"
"github.com/golang/protobuf/proto"
pb "github.com/iotaledger/goshimmer/packages/autopeering/salt/proto"
)
// SaltByteSize specifies the number of bytes used for the salt.
const SaltByteSize = 20
// Salt encapsulates high level functions around salt management.
type Salt struct {
bytes []byte // value of the salt
expirationTime time.Time // expiration time of the salt
mutex sync.RWMutex
}
// NewSalt generates a new salt given a lifetime duration
func NewSalt(lifetime time.Duration) (salt *Salt, err error) {
salt = &Salt{
bytes: make([]byte, SaltByteSize),
expirationTime: time.Now().Add(lifetime),
}
if _, err = rand.Read(salt.bytes); err != nil {
return nil, err
}
return salt, err
}
func (s *Salt) GetBytes() []byte {
s.mutex.RLock()
defer s.mutex.RUnlock()
return s.bytes
}
func (s *Salt) GetExpiration() time.Time {
s.mutex.RLock()
defer s.mutex.RUnlock()
return s.expirationTime
}
// Expired returns true if the given salt expired
func (s *Salt) Expired() bool {
return time.Now().After(s.GetExpiration())
}
// ToProto encodes the Salt into a proto buffer Salt message
func (s *Salt) ToProto() *pb.Salt {
return &pb.Salt{
Bytes: s.bytes,
ExpTime: uint64(s.expirationTime.Unix()),
}
}
// FromProto decodes a given proto buffer Salt message (in) and returns the corresponding Salt.
func FromProto(in *pb.Salt) (*Salt, error) {
if l := len(in.GetBytes()); l != SaltByteSize {
return nil, fmt.Errorf("invalid salt length: %d, need %d", l, SaltByteSize)
}
out := &Salt{
bytes: in.GetBytes(),
expirationTime: time.Unix(int64(in.GetExpTime()), 0),
}
return out, nil
}
// Marshal serializes a given salt (s) into a slice of bytes (data)
func (s *Salt) Marshal() ([]byte, error) {
return proto.Marshal(s.ToProto())
}
// Unmarshal de-serializes a given slice of bytes (data) into a Salt.
func Unmarshal(data []byte) (*Salt, error) {
s := &pb.Salt{}
if err := proto.Unmarshal(data, s); err != nil {
return nil, err
}
return FromProto(s)
}