Improved mock PeerID
This commit is contained in:
parent
c02f068d1d
commit
9e362fb8c4
13
conn.go
13
conn.go
|
@ -26,6 +26,7 @@ type connConfig struct {
|
||||||
maAddr ma.Multiaddr
|
maAddr ma.Multiaddr
|
||||||
addr net.Addr
|
addr net.Addr
|
||||||
isServer bool
|
isServer bool
|
||||||
|
remoteID peer.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
func newConnConfig(transport *Transport, maAddr ma.Multiaddr, isServer bool) (*connConfig, error) {
|
func newConnConfig(transport *Transport, maAddr ma.Multiaddr, isServer bool) (*connConfig, error) {
|
||||||
|
@ -310,26 +311,26 @@ func (c *Conn) awaitAccept() (*datachannel.DataChannel, error) {
|
||||||
|
|
||||||
// LocalPeer returns our peer ID
|
// LocalPeer returns our peer ID
|
||||||
func (c *Conn) LocalPeer() peer.ID {
|
func (c *Conn) LocalPeer() peer.ID {
|
||||||
// TODO: How to form a peer ID?
|
// TODO: Base on WebRTC security?
|
||||||
return peer.ID("")
|
return c.config.transport.localID
|
||||||
}
|
}
|
||||||
|
|
||||||
// LocalPrivateKey returns our private key
|
// LocalPrivateKey returns our private key
|
||||||
func (c *Conn) LocalPrivateKey() ic.PrivKey {
|
func (c *Conn) LocalPrivateKey() ic.PrivKey {
|
||||||
// TODO: Expose from pions/webrtc?
|
// TODO: Base on WebRTC security?
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemotePeer returns the peer ID of the remote peer.
|
// RemotePeer returns the peer ID of the remote peer.
|
||||||
func (c *Conn) RemotePeer() peer.ID {
|
func (c *Conn) RemotePeer() peer.ID {
|
||||||
// TODO: How to form a peer ID?
|
// TODO: Base on WebRTC security?
|
||||||
return peer.ID("")
|
return c.config.remoteID
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemotePublicKey returns the public key of the remote peer.
|
// RemotePublicKey returns the public key of the remote peer.
|
||||||
func (c *Conn) RemotePublicKey() ic.PubKey {
|
func (c *Conn) RemotePublicKey() ic.PubKey {
|
||||||
// TODO: Expose from pions/webrtc?
|
// TODO: Base on WebRTC security?
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ import (
|
||||||
type Transport struct {
|
type Transport struct {
|
||||||
webrtcOptions webrtc.RTCConfiguration
|
webrtcOptions webrtc.RTCConfiguration
|
||||||
muxer smux.Transport
|
muxer smux.Transport
|
||||||
|
localID peer.ID
|
||||||
api *webrtc.API
|
api *webrtc.API
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,10 +26,12 @@ func NewTransport(webrtcOptions webrtc.RTCConfiguration, muxer smux.Transport) *
|
||||||
s := webrtc.SettingEngine{}
|
s := webrtc.SettingEngine{}
|
||||||
// Use Detach data channels mode
|
// Use Detach data channels mode
|
||||||
s.DetachDataChannels()
|
s.DetachDataChannels()
|
||||||
|
|
||||||
api := webrtc.NewAPI(webrtc.WithSettingEngine(s))
|
api := webrtc.NewAPI(webrtc.WithSettingEngine(s))
|
||||||
return &Transport{
|
return &Transport{
|
||||||
webrtcOptions: webrtcOptions,
|
webrtcOptions: webrtcOptions,
|
||||||
muxer: muxer, // TODO: Make the muxer optional
|
muxer: muxer, // TODO: Make the muxer optional
|
||||||
|
localID: peer.ID(1),
|
||||||
api: api,
|
api: api,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,6 +53,8 @@ func (t *Transport) Dial(ctx context.Context, raddr ma.Multiaddr, p peer.ID) (tp
|
||||||
return nil, fmt.Errorf("failed to get dial args: %v", err)
|
return nil, fmt.Errorf("failed to get dial args: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cfg.remoteID = p
|
||||||
|
|
||||||
conn, err := dial(ctx, cfg)
|
conn, err := dial(ctx, cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to create connection: %v", err)
|
return nil, fmt.Errorf("failed to create connection: %v", err)
|
||||||
|
|
Loading…
Reference in New Issue