Improved mock PeerID

This commit is contained in:
backkem 2019-02-25 20:36:24 +01:00 committed by Michiel De Backker
parent c02f068d1d
commit 9e362fb8c4
2 changed files with 12 additions and 6 deletions

13
conn.go
View File

@ -26,6 +26,7 @@ type connConfig struct {
maAddr ma.Multiaddr
addr net.Addr
isServer bool
remoteID peer.ID
}
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
func (c *Conn) LocalPeer() peer.ID {
// TODO: How to form a peer ID?
return peer.ID("")
// TODO: Base on WebRTC security?
return c.config.transport.localID
}
// LocalPrivateKey returns our private key
func (c *Conn) LocalPrivateKey() ic.PrivKey {
// TODO: Expose from pions/webrtc?
// TODO: Base on WebRTC security?
return nil
}
// RemotePeer returns the peer ID of the remote peer.
func (c *Conn) RemotePeer() peer.ID {
// TODO: How to form a peer ID?
return peer.ID("")
// TODO: Base on WebRTC security?
return c.config.remoteID
}
// RemotePublicKey returns the public key of the remote peer.
func (c *Conn) RemotePublicKey() ic.PubKey {
// TODO: Expose from pions/webrtc?
// TODO: Base on WebRTC security?
return nil
}

View File

@ -16,6 +16,7 @@ import (
type Transport struct {
webrtcOptions webrtc.RTCConfiguration
muxer smux.Transport
localID peer.ID
api *webrtc.API
}
@ -25,10 +26,12 @@ func NewTransport(webrtcOptions webrtc.RTCConfiguration, muxer smux.Transport) *
s := webrtc.SettingEngine{}
// Use Detach data channels mode
s.DetachDataChannels()
api := webrtc.NewAPI(webrtc.WithSettingEngine(s))
return &Transport{
webrtcOptions: webrtcOptions,
muxer: muxer, // TODO: Make the muxer optional
localID: peer.ID(1),
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)
}
cfg.remoteID = p
conn, err := dial(ctx, cfg)
if err != nil {
return nil, fmt.Errorf("failed to create connection: %v", err)