ion-sfu icon indicating copy to clipboard operation
ion-sfu copied to clipboard

Abort the relay,I need a demo.

Open luoshuai5 opened this issue 4 years ago • 9 comments

ION-SFU integration

ION-SFU offers some convenience methods for relaying peers in a very simple way.

To relay a peer just call Peer.Publisher().Relay(...) then signal the data to the remote SFU and ingest the data using:

session.AddRelayPeer(peerID string, signalData []byte) ([]byte, error)

set the []byte response from the method as the response of the signaling. And is ready, everytime a peer joins to the new SFU will negotiate the relayed stream.

When will I call Peer.Publisher().Relay(...) ? When will I call session.AddRelayPeer(peerID string, signalData []byte) ([]byte, error) ?

luoshuai5 avatar Dec 09 '21 04:12 luoshuai5

You can try to do it yourself Try to write an information service, manage all sFU nodes, register your node information in the information service, call other SFU node Relay and AddRelay method through GRPC, Relay communication.

upeartaker avatar Dec 16 '21 01:12 upeartaker

@upeartaker Thanks for the answer, i'd like to help if you can PR a example :)

adwpc avatar Dec 19 '21 08:12 adwpc

Of course, I will propose a PR to you sometime @adwpc

upeartaker avatar Dec 19 '21 09:12 upeartaker

@upeartaker yes, i done it, but it not work. when a publisher join session, I call Peer.Publisher().Relay(...),then, send the data to other sfu by RPC, other sfu get the data and call session.AddRelayPeer(peerID string, signalData []byte) ([]byte, error).

luoshuai5 avatar Dec 20 '21 02:12 luoshuai5

Emmm, I think it is possible that your two SFU service exposed UDP port is single port, change to random port try. I have also encountered this problem, in ORTC mode, the relay operation uses a single port, there are some weird problems.

The code I implemented under the signal service looks something like this

                             c, err := NewInvoke(e.Addr, "")
			if err != nil {
				sfu.Logger.Error(err, "init relay grpc invoke failed")
				return status.Errorf(codes.Internal, "join error %s", err)
			}
			_, err = peer.Publisher().Relay(func(meta relay.PeerMeta, signal []byte) ([]byte, error) {
				//	 record
				s.edgeServer.relayServer.AddRelay(&RelayInfo{
					EdgeName: e.EdgeName,
					EdgeAddr: e.Addr,
					Pid:      peer.ID(),
				})
				answer, err := c.AddRelayPeer(s.edgeServer.relayServer.RelayAddr, peer.ID(), payload.Join.Sid, signal)
				if err != nil {
					sfu.Logger.Error(err, "add relay peer grpc invoke failed")
					return nil, err
				}
				return answer, nil
			}, sfu.RelayWithFanOutDataChannels(), sfu.RelayWithSenderReports(), sfu.RelayWithMiddlewareDatachannel())

			if err != nil {
				sfu.Logger.Error(err, "invoke relay method failed")
				return status.Errorf(codes.Internal, "join error %s", err)
			}

invoke is grpc client

upeartaker avatar Dec 20 '21 02:12 upeartaker

@upeartaker en, it still not work. this my code

    p.Publisher().Relay(func(meta relay.PeerMeta, signal []byte) ([]byte, error) {  \n
			return AddRelay("192.168.1.157:8888", meta.PeerID, meta.SessionID, signal)  // connect to other sfu by RPC \n
		}, sfu.RelayWithFanOutDataChannels(), sfu.RelayWithSenderReports()) \n

other sfu err log:

2021-12-20 11:11:47.917] [INFO] [main.go:94] => Config file loaded file=config.toml v=0
[2021-12-20 11:11:47.917] [INFO] [main.go:151] => --- Starting SFU Node --- v=0
[2021-12-20 11:11:47.917] [INFO] [main.go:190] => Started listening addr=http://:7000 v=0
[2021-12-20 11:11:47.917] [INFO] [relay.go:37] => Started listening addr=0.0.0.0:8888 v=0
[2021-12-20 11:12:02.378] [INFO] [relay.go:76] => GetSignalData peer=ckxe3r00r0001hsswnnek1s4e session=ion v=0
[2021-12-20 11:12:11.245] [INFO] [peer.go:291] => PeerLocal join SessionLocal peer_id=ckxe3r5kd0000j934ft9fodid session_id=ion v=0
[2021-12-20 11:12:11.245] [INFO] [peer.go:305] => PeerLocal got offer peer_id=ckxe3r5kd0000j934ft9fodid v=0
[2021-12-20 11:12:11.247] [INFO] [peer.go:316] => PeerLocal send answer peer_id=ckxe3r5kd0000j934ft9fodid v=0
[2021-12-20 11:12:11.247] [INFO] [peer.go:349] => PeerLocal trickle peer_id=ckxe3r5kd0000j934ft9fodid v=0
[2021-12-20 11:12:11.247] [INFO] [peer.go:349] => PeerLocal trickle peer_id=ckxe3r5kd0000j934ft9fodid v=0
[2021-12-20 11:12:11.247] [INFO] [peer.go:349] => PeerLocal trickle peer_id=ckxe3r5kd0000j934ft9fodid v=0
[2021-12-20 11:12:11.497] [INFO] [peer.go:239] => Send offer peer_id=ckxe3r5kd0000j934ft9fodid v=0
[2021-12-20 11:12:11.499] [INFO] [peer.go:329] => PeerLocal got answer peer_id=ckxe3r5kd0000j934ft9fodid v=0
[2021-12-20 11:12:11.500] [INFO] [peer.go:349] => PeerLocal trickle peer_id=ckxe3r5kd0000j934ft9fodid v=0
[2021-12-20 11:12:11.500] [INFO] [peer.go:349] => PeerLocal trickle peer_id=ckxe3r5kd0000j934ft9fodid v=0
[2021-12-20 11:12:11.500] [INFO] [peer.go:349] => PeerLocal trickle peer_id=ckxe3r5kd0000j934ft9fodid v=0
[2021-12-20 11:12:32.477] [ERROR] [relay.go:286] => Error starting relay error="connecting canceled by caller"

luoshuai5 avatar Dec 20 '21 03:12 luoshuai5

[2021-12-20 11:12:32.477] [ERROR] [relay.go:286] => Error starting relay error="connecting canceled by caller" @luoshuai5 Your problem appears to be that two SFU nodes are disconnected from the network. I do not know the deployment status of your two SFU nodes. If you are in pod form, try using Host Pod and add NAT1to1 while portrange is on

If that doesn't solve your problem, I suggest you use a packet capture tool to analyze your STUN server mappings

upeartaker avatar Dec 20 '21 03:12 upeartaker

@upeartaker all peers and sfu nodes use same LAN.

luoshuai5 avatar Dec 20 '21 04:12 luoshuai5

@upeartaker en, it still not work. this my code

    p.Publisher().Relay(func(meta relay.PeerMeta, signal []byte) ([]byte, error) {  \n
   		return AddRelay("192.168.1.157:8888", meta.PeerID, meta.SessionID, signal)  // connect to other sfu by RPC \n
   	}, sfu.RelayWithFanOutDataChannels(), sfu.RelayWithSenderReports()) \n

other sfu err log:

2021-12-20 11:11:47.917] [INFO] [main.go:94] => Config file loaded file=config.toml v=0
[2021-12-20 11:11:47.917] [INFO] [main.go:151] => --- Starting SFU Node --- v=0
[2021-12-20 11:11:47.917] [INFO] [main.go:190] => Started listening addr=http://:7000 v=0
[2021-12-20 11:11:47.917] [INFO] [relay.go:37] => Started listening addr=0.0.0.0:8888 v=0
[2021-12-20 11:12:02.378] [INFO] [relay.go:76] => GetSignalData peer=ckxe3r00r0001hsswnnek1s4e session=ion v=0
[2021-12-20 11:12:11.245] [INFO] [peer.go:291] => PeerLocal join SessionLocal peer_id=ckxe3r5kd0000j934ft9fodid session_id=ion v=0
[2021-12-20 11:12:11.245] [INFO] [peer.go:305] => PeerLocal got offer peer_id=ckxe3r5kd0000j934ft9fodid v=0
[2021-12-20 11:12:11.247] [INFO] [peer.go:316] => PeerLocal send answer peer_id=ckxe3r5kd0000j934ft9fodid v=0
[2021-12-20 11:12:11.247] [INFO] [peer.go:349] => PeerLocal trickle peer_id=ckxe3r5kd0000j934ft9fodid v=0
[2021-12-20 11:12:11.247] [INFO] [peer.go:349] => PeerLocal trickle peer_id=ckxe3r5kd0000j934ft9fodid v=0
[2021-12-20 11:12:11.247] [INFO] [peer.go:349] => PeerLocal trickle peer_id=ckxe3r5kd0000j934ft9fodid v=0
[2021-12-20 11:12:11.497] [INFO] [peer.go:239] => Send offer peer_id=ckxe3r5kd0000j934ft9fodid v=0
[2021-12-20 11:12:11.499] [INFO] [peer.go:329] => PeerLocal got answer peer_id=ckxe3r5kd0000j934ft9fodid v=0
[2021-12-20 11:12:11.500] [INFO] [peer.go:349] => PeerLocal trickle peer_id=ckxe3r5kd0000j934ft9fodid v=0
[2021-12-20 11:12:11.500] [INFO] [peer.go:349] => PeerLocal trickle peer_id=ckxe3r5kd0000j934ft9fodid v=0
[2021-12-20 11:12:11.500] [INFO] [peer.go:349] => PeerLocal trickle peer_id=ckxe3r5kd0000j934ft9fodid v=0
[2021-12-20 11:12:32.477] [ERROR] [relay.go:286] => Error starting relay error="connecting canceled by caller"

I encountered the same error while playing with SFUa SFUb (connecting canceled by caller), on my SFUa side (the one as local SFU to call peer.Publisher.Relay) the printout is actually something else. (missing uFrag).

and after digging into the detailed response (content of signal returning from remote SFU), for my specific case the failure is parsing the response from remote SFU. So maybe you can check the signal value on both side, hopefully this can help

sweetbasil-bill avatar Aug 30 '22 09:08 sweetbasil-bill