2018-10-08 16:09:37 +01:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package node
|
|
|
|
|
|
|
|
import (
|
2018-10-11 22:41:58 +01:00
|
|
|
"context"
|
|
|
|
|
|
|
|
"storj.io/storj/pkg/provider"
|
2018-10-08 16:09:37 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// ID is the unique identifier of a Node in the overlay network
|
|
|
|
type ID string
|
|
|
|
|
2018-10-11 22:41:58 +01:00
|
|
|
// NewFullIdentity creates a new ID for nodes with difficulty and concurrency params
|
|
|
|
func NewFullIdentity(ctx context.Context, difficulty uint16, concurrency uint) (*provider.FullIdentity, error) {
|
2018-11-01 15:48:43 +00:00
|
|
|
ca, err := provider.NewCA(ctx, provider.NewCAOptions{
|
|
|
|
Difficulty: difficulty,
|
|
|
|
Concurrency: concurrency,
|
|
|
|
})
|
2018-10-11 22:41:58 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
identity, err := ca.NewIdentity()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return identity, err
|
|
|
|
}
|
|
|
|
|
2018-10-08 16:09:37 +01:00
|
|
|
// String transforms the ID to a string type
|
|
|
|
func (n *ID) String() string {
|
|
|
|
return string(*n)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bytes transforms the ID to type []byte
|
|
|
|
func (n *ID) Bytes() []byte {
|
|
|
|
return []byte(*n)
|
|
|
|
}
|
|
|
|
|
|
|
|
// IDFromString trsansforms a string to a ID
|
|
|
|
func IDFromString(s string) *ID {
|
|
|
|
n := ID(s)
|
|
|
|
return &n
|
|
|
|
}
|