2015-11-12 00:15:47 +00:00
|
|
|
package testutil
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
ci "github.com/ipfs/go-libp2p/p2p/crypto"
|
|
|
|
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
2016-03-03 21:03:24 +00:00
|
|
|
ma "gx/ipfs/QmcobAGsCjYt5DXoq9et9L8yR8er7o7Cu3DTvpaq12jYSz/go-multiaddr"
|
2015-11-12 00:15:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Identity interface {
|
|
|
|
Address() ma.Multiaddr
|
|
|
|
ID() peer.ID
|
|
|
|
PrivateKey() ci.PrivKey
|
|
|
|
PublicKey() ci.PubKey
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO add a cheaper way to generate identities
|
|
|
|
|
|
|
|
func RandIdentity() (Identity, error) {
|
|
|
|
p, err := RandPeerNetParams()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &identity{*p}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func RandIdentityOrFatal(t *testing.T) Identity {
|
|
|
|
p, err := RandPeerNetParams()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
return &identity{*p}
|
|
|
|
}
|
|
|
|
|
|
|
|
// identity is a temporary shim to delay binding of PeerNetParams.
|
|
|
|
type identity struct {
|
|
|
|
PeerNetParams
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *identity) ID() peer.ID {
|
|
|
|
return p.PeerNetParams.ID
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *identity) Address() ma.Multiaddr {
|
|
|
|
return p.Addr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *identity) PrivateKey() ci.PrivKey {
|
|
|
|
return p.PrivKey
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *identity) PublicKey() ci.PubKey {
|
|
|
|
return p.PubKey
|
|
|
|
}
|