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
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue