diff --git a/lib/nodes/go/go.mod b/lib/nodes/go/go.mod index a1c8a569a..0f9071218 100644 --- a/lib/nodes/go/go.mod +++ b/lib/nodes/go/go.mod @@ -2,4 +2,9 @@ module git.rwth-aachen.de/acs/public/villas/node go 1.16 -require github.com/mattn/go-pointer v0.0.1 +require ( + github.com/gorilla/websocket v1.5.0 // indirect + github.com/mattn/go-pointer v0.0.1 + github.com/pion/webrtc/v3 v3.1.24 // indirect + github.com/sirupsen/logrus v1.8.1 // indirect +) diff --git a/lib/nodes/go/go.sum b/lib/nodes/go/go.sum index 1fdefeab4..6459724c1 100644 --- a/lib/nodes/go/go.sum +++ b/lib/nodes/go/go.sum @@ -1,2 +1,154 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= +github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= +github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/mattn/go-pointer v0.0.1 h1:n+XhsuGeVO6MEAp7xyEukFINEa+Quek5psIR/ylA6o0= github.com/mattn/go-pointer v0.0.1/go.mod h1:2zXcozF6qYGgmsG+SeTZz3oAbFLdD3OWqnUbNvJZAlc= +github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= +github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= +github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= +github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= +github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= +github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= +github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= +github.com/pion/datachannel v1.5.2 h1:piB93s8LGmbECrpO84DnkIVWasRMk3IimbcXkTQLE6E= +github.com/pion/datachannel v1.5.2/go.mod h1:FTGQWaHrdCwIJ1rw6xBIfZVkslikjShim5yr05XFuCQ= +github.com/pion/dtls/v2 v2.1.2/go.mod h1:o6+WvyLDAlXF7YiPB/RlskRoeK+/JtuaZa5emwQcWus= +github.com/pion/dtls/v2 v2.1.3 h1:3UF7udADqous+M2R5Uo2q/YaP4EzUoWKdfX2oscCUio= +github.com/pion/dtls/v2 v2.1.3/go.mod h1:o6+WvyLDAlXF7YiPB/RlskRoeK+/JtuaZa5emwQcWus= +github.com/pion/ice/v2 v2.2.1 h1:R3MeuJZpU1ty3diPqpD5OxaxcZ15eprAc+EtUiSoFxg= +github.com/pion/ice/v2 v2.2.1/go.mod h1:Op8jlPtjeiycsXh93Cs4jK82C9j/kh7vef6ztIOvtIQ= +github.com/pion/interceptor v0.1.7 h1:HThW0tIIKT9RRoDWGURe8rlZVOx0fJHxBHpA0ej0+bo= +github.com/pion/interceptor v0.1.7/go.mod h1:Lh3JSl/cbJ2wP8I3ccrjh1K/deRGRn3UlSPuOTiHb6U= +github.com/pion/logging v0.2.2 h1:M9+AIj/+pxNsDfAT64+MAVgJO0rsyLnoJKCqf//DoeY= +github.com/pion/logging v0.2.2/go.mod h1:k0/tDVsRCX2Mb2ZEmTqNa7CWsQPc+YYCB7Q+5pahoms= +github.com/pion/mdns v0.0.5 h1:Q2oj/JB3NqfzY9xGZ1fPzZzK7sDSD8rZPOvcIQ10BCw= +github.com/pion/mdns v0.0.5/go.mod h1:UgssrvdD3mxpi8tMxAXbsppL3vJ4Jipw1mTCW+al01g= +github.com/pion/randutil v0.1.0 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA= +github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8= +github.com/pion/rtcp v1.2.6/go.mod h1:52rMNPWFsjr39z9B9MhnkqhPLoeHTv1aN63o/42bWE0= +github.com/pion/rtcp v1.2.9 h1:1ujStwg++IOLIEoOiIQ2s+qBuJ1VN81KW+9pMPsif+U= +github.com/pion/rtcp v1.2.9/go.mod h1:qVPhiCzAm4D/rxb6XzKeyZiQK69yJpbUDJSF7TgrqNo= +github.com/pion/rtp v1.7.0/go.mod h1:bDb5n+BFZxXx0Ea7E5qe+klMuqiBrP+w8XSjiWtCUko= +github.com/pion/rtp v1.7.4 h1:4dMbjb1SuynU5OpA3kz1zHK+u+eOCQjW3MAeVHf1ODA= +github.com/pion/rtp v1.7.4/go.mod h1:bDb5n+BFZxXx0Ea7E5qe+klMuqiBrP+w8XSjiWtCUko= +github.com/pion/sctp v1.8.0/go.mod h1:xFe9cLMZ5Vj6eOzpyiKjT9SwGM4KpK/8Jbw5//jc+0s= +github.com/pion/sctp v1.8.2 h1:yBBCIrUMJ4yFICL3RIvR4eh/H2BTTvlligmSTy+3kiA= +github.com/pion/sctp v1.8.2/go.mod h1:xFe9cLMZ5Vj6eOzpyiKjT9SwGM4KpK/8Jbw5//jc+0s= +github.com/pion/sdp/v3 v3.0.4 h1:2Kf+dgrzJflNCSw3TV5v2VLeI0s/qkzy2r5jlR0wzf8= +github.com/pion/sdp/v3 v3.0.4/go.mod h1:bNiSknmJE0HYBprTHXKPQ3+JjacTv5uap92ueJZKsRk= +github.com/pion/srtp/v2 v2.0.5 h1:ks3wcTvIUE/GHndO3FAvROQ9opy0uLELpwHJaQ1yqhQ= +github.com/pion/srtp/v2 v2.0.5/go.mod h1:8k6AJlal740mrZ6WYxc4Dg6qDqqhxoRG2GSjlUhDF0A= +github.com/pion/stun v0.3.5 h1:uLUCBCkQby4S1cf6CGuR9QrVOKcvUwFeemaC865QHDg= +github.com/pion/stun v0.3.5/go.mod h1:gDMim+47EeEtfWogA37n6qXZS88L5V6LqFcf+DZA2UA= +github.com/pion/transport v0.12.2/go.mod h1:N3+vZQD9HlDP5GWkZ85LohxNsDcNgofQmyL6ojX5d8Q= +github.com/pion/transport v0.12.3/go.mod h1:OViWW9SP2peE/HbwBvARicmAVnesphkNkCVZIWJ6q9A= +github.com/pion/transport v0.13.0 h1:KWTA5ZrQogizzYwPEciGtHPLwpAjE91FgXnyu+Hv2uY= +github.com/pion/transport v0.13.0/go.mod h1:yxm9uXpK9bpBBWkITk13cLo1y5/ur5VQpG22ny6EP7g= +github.com/pion/turn/v2 v2.0.8 h1:KEstL92OUN3k5k8qxsXHpr7WWfrdp7iJZHx99ud8muw= +github.com/pion/turn/v2 v2.0.8/go.mod h1:+y7xl719J8bAEVpSXBXvTxStjJv3hbz9YFflvkpcGPw= +github.com/pion/udp v0.1.1 h1:8UAPvyqmsxK8oOjloDk4wUt63TzFe9WEJkg5lChlj7o= +github.com/pion/udp v0.1.1/go.mod h1:6AFo+CMdKQm7UiA0eUPA8/eVCTx8jBIITLZHc9DWX5M= +github.com/pion/webrtc/v3 v3.1.24 h1:s9PuwisrgHe1FTqfwK4p3T7rXtAHaUNhycbdMjADT28= +github.com/pion/webrtc/v3 v3.1.24/go.mod h1:mO/yv7fBN3Lp7YNlnYcTj1jtpvNvssJG+7eh6itZ4xM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sclevine/agouti v3.0.0+incompatible/go.mod h1:b4WX9W9L1sfQKXeJf1mUTLZKJ48R1S7H23Ji7oFO5Bw= +github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= +github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838 h1:71vQrMauZZhcTVK6KdYM+rklehEEwb3E+ZhaE5jrPrE= +golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201201195509-5d6afe98e0b7/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20211201190559-0a0e4e1bb54c/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk= +golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM= +golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/lib/nodes/go/log.c b/lib/nodes/go/log.c new file mode 100644 index 000000000..e69de29bb diff --git a/lib/nodes/go/log.cpp b/lib/nodes/go/log.cpp new file mode 100644 index 000000000..55adaa368 --- /dev/null +++ b/lib/nodes/go/log.cpp @@ -0,0 +1,17 @@ +#include + +extern "C" { + #include "log.h" +} + +using namespace villas; + +void log(char *logger, int level, char *msg); +{ + auto logger = logging.get(logger); + + spdlog::log(level, "{}", msg); + + free(logger); + free(msg); +} diff --git a/lib/nodes/go/log.h b/lib/nodes/go/log.h new file mode 100644 index 000000000..725c92ffa --- /dev/null +++ b/lib/nodes/go/log.h @@ -0,0 +1 @@ +void log(char *logger, int level, char *msg); diff --git a/lib/nodes/go/logger.go b/lib/nodes/go/logger.go new file mode 100644 index 000000000..f430f57d3 --- /dev/null +++ b/lib/nodes/go/logger.go @@ -0,0 +1,81 @@ +package main + +//// #include "log.h" +import "C" +import "fmt" + +type LogLevel int + +const ( + // https://github.com/gabime/spdlog/blob/a51b4856377a71f81b6d74b9af459305c4c644f8/include/spdlog/common.h#L76 + LogLevelTrace LogLevel = iota + LogLevelDebug LogLevel = iota + LogLevelInfo LogLevel = iota + LogLevelWarn LogLevel = iota + LogLevelError LogLevel = iota + LogLevelCritical LogLevel = iota + LogLevelOff LogLevel = iota +) + +type Logger struct { + Name string + + cName *C.char +} + +func GetLogger(name string) *Logger { + return &Logger{ + Name: name, + } +} + +func (l *Logger) log(lvl LogLevel, msg string) { + cMsg := C.CString(msg) + C.log(l.cName, lvl, cMsg) + C.free(cMsg) +} + +func (l *Logger) Trace(msg string) { + l.log(LogLevelTrace, msg) +} + +func (l *Logger) Info(msg string) { + l.log(LogLevelInfo, msg) +} + +func (l *Logger) Warn(msg string) { + l.log(LogLevelWarn, msg) +} + +func (l *Logger) Error(msg string) { + l.log(LogLevelError, msg) +} + +func (l *Logger) Critical(msg string) { + l.log(LogLevelCritical, msg) +} + +func (l *Logger) Tracef(format string, args ...interface{}) { + msg := fmt.Sprintf(format, args...) + l.log(LogLevelTrace, msg) +} + +func (l *Logger) Infof(format string, args ...interface{}) { + msg := fmt.Sprintf(format, args...) + l.log(LogLevelInfo, msg) +} + +func (l *Logger) Warnf(format string, args ...interface{}) { + msg := fmt.Sprintf(format, args...) + l.log(LogLevelWarn, msg) +} + +func (l *Logger) Errorf(format string, args ...interface{}) { + msg := fmt.Sprintf(format, args...) + l.log(LogLevelError, msg) +} + +func (l *Logger) Criticalf(format string, args ...interface{}) { + msg := fmt.Sprintf(format, args...) + l.log(LogLevelCritical, msg) +} diff --git a/lib/nodes/go/pkg/nodes/webrtc/backoff.go b/lib/nodes/go/pkg/nodes/webrtc/backoff.go new file mode 100644 index 000000000..8aeb7a09f --- /dev/null +++ b/lib/nodes/go/pkg/nodes/webrtc/backoff.go @@ -0,0 +1,33 @@ +package webrtc + +import "time" + +var ( + DefaultExponentialBackoff = ExponentialBackoff{ + Factor: 1.5, + Maximum: 1 * time.Minute, + Initial: 1 * time.Second, + Duration: 1 * time.Second, + } +) + +type ExponentialBackoff struct { + Factor float32 + Maximum time.Duration + Initial time.Duration + + Duration time.Duration +} + +func (e *ExponentialBackoff) Next() time.Duration { + e.Duration = time.Duration(1.5 * float32(e.Duration)).Round(time.Second) + if e.Duration > e.Maximum { + e.Duration = e.Maximum + } + + return e.Duration +} + +func (e *ExponentialBackoff) Reset() { + e.Duration = e.Initial +} diff --git a/lib/nodes/go/pkg/nodes/webrtc/client.go b/lib/nodes/go/pkg/nodes/webrtc/client.go new file mode 100644 index 000000000..37de3ff9f --- /dev/null +++ b/lib/nodes/go/pkg/nodes/webrtc/client.go @@ -0,0 +1,164 @@ +package webrtc + +import ( + "fmt" + "net/url" + "time" + + "github.com/gorilla/websocket" + "github.com/sirupsen/logrus" +) + +type SignalingClient struct { + *websocket.Conn + + URL *url.URL + + done chan struct{} + + isClosing bool + backoff ExponentialBackoff + + messageCallbacks []func(msg *SignalingMessage) + connectCallbacks []func() + disconnectCallbacks []func() +} + +func NewSignalingClient(u *url.URL) (*SignalingClient, error) { + c := &SignalingClient{ + messageCallbacks: []func(msg *SignalingMessage){}, + connectCallbacks: []func(){}, + disconnectCallbacks: []func(){}, + isClosing: false, + backoff: DefaultExponentialBackoff, + URL: u, + } + + return c, nil +} + +func (c *SignalingClient) OnConnect(cb func()) { + c.connectCallbacks = append(c.connectCallbacks, cb) +} + +func (c *SignalingClient) OnDisconnect(cb func()) { + c.disconnectCallbacks = append(c.connectCallbacks, cb) +} + +func (c *SignalingClient) OnMessage(cb func(msg *SignalingMessage)) { + c.messageCallbacks = append(c.messageCallbacks, cb) +} + +func (c *SignalingClient) SendSignalingMessage(msg *SignalingMessage) error { + logrus.Infof("Sending signaling message: %s", msg) + return c.Conn.WriteJSON(msg) +} + +func (c *SignalingClient) Close() error { + // Return immediatly if there is no open connection + if c.Conn == nil { + return nil + } + + c.isClosing = true + + // Cleanly close the connection by sending a close message and then + // waiting (with timeout) for the server to close the connection. + err := c.Conn.WriteControl(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""), time.Now().Add(5*time.Second)) + if err != nil { + return fmt.Errorf("failed to send close message: %s", err) + } + + select { + case <-c.done: + logrus.Infof("Connection closed") + case <-time.After(3 * time.Second): + logrus.Warn("Timed-out waiting for connection close") + } + + return nil +} + +func (c *SignalingClient) Connect() error { + var err error + + dialer := websocket.Dialer{ + HandshakeTimeout: 1 * time.Second, + } + + c.Conn, _, err = dialer.Dial(c.URL.String(), nil) + if err != nil { + return fmt.Errorf("failed to dial %s: %w", c.URL, err) + } + + for _, cb := range c.connectCallbacks { + cb() + } + + go c.read() + + // Reset reconnect timer + c.backoff.Reset() + + c.done = make(chan struct{}) + + return nil +} + +func (c *SignalingClient) ConnectWithBackoff() error { + t := time.NewTimer(c.backoff.Duration) + for range t.C { + if err := c.Connect(); err != nil { + t.Reset(c.backoff.Next()) + + logrus.Errorf("Failed to connect: %s. Reconnecting in %s", err, c.backoff.Duration) + } else { + break + } + } + + return nil +} + +func (c *SignalingClient) read() { + for { + msg := &SignalingMessage{} + if err := c.Conn.ReadJSON(msg); err != nil { + if websocket.IsCloseError(err, websocket.CloseGoingAway, websocket.CloseNormalClosure) { + + } else { + logrus.Errorf("Failed to read: %s", err) + } + break + } + + logrus.Infof("Received signaling message: %s", msg) + + for _, cb := range c.messageCallbacks { + cb(msg) + } + } + + c.closed() +} + +func (c *SignalingClient) closed() { + if err := c.Conn.Close(); err != nil { + logrus.Errorf("Failed to close connection: %s", err) + } + + c.Conn = nil + + for _, cb := range c.disconnectCallbacks { + cb() + } + + close(c.done) + + if c.isClosing { + logrus.Infof("Connection closed") + } else { + logrus.Warnf("Connection lost. Reconnecting in %s", c.backoff.Duration) + go c.ConnectWithBackoff() + } +} diff --git a/lib/nodes/go/pkg/nodes/webrtc/node.go b/lib/nodes/go/pkg/nodes/webrtc/node.go new file mode 100644 index 000000000..dfa0232c8 --- /dev/null +++ b/lib/nodes/go/pkg/nodes/webrtc/node.go @@ -0,0 +1,179 @@ +package webrtc + +import ( + "encoding/json" + "errors" + "fmt" + "net/url" + "strings" + + node "git.rwth-aachen.de/acs/public/villas/node/pkg" + "github.com/pion/webrtc/v3" +) + +var ( + DefaultConfig = Config{ + Server: &url.URL{ + Scheme: "wss", + Host: "https://ws-signal.villas.k8s.eonerc.rwth-aachen.de", + }, + WebRTC: webrtc.Configuration{ + ICEServers: []webrtc.ICEServer{ + { + URLs: []string{"stun:stun.l.google.com:19302"}, + }, + }, + }, + } +) + +type Node struct { + node.Node + + *PeerConnection + + Config Config + + receive chan []byte + send chan []byte + + stop chan struct{} +} + +type Config struct { + Server *url.URL + Session string + + WebRTC webrtc.Configuration +} + +func NewNode() node.Node { + return &Node{ + stop: make(chan struct{}), + send: make(chan []byte), + receive: make(chan []byte), + + Config: DefaultConfig, + } +} + +func (n *Node) Parse(c []byte) error { + var err error + var cfg struct { + Session *string `json:"session"` + Server *string `json:"server,omitempty"` + Ice *struct { + Servers []struct { + URLs []string `json:"urls,omitempty"` + Username *string `json:"username,omitempty"` + Password *string `json:"password,omitempty"` + } `json:"servers,omitempty"` + } `json:"ice,omitempty"` + } + + if err := json.Unmarshal(c, &cfg); err != nil { + return fmt.Errorf("failed to unmarshal config: %w", err) + } + + if cfg.Session == nil || *cfg.Session == "" { + return errors.New("missing or invalid session name") + } else { + n.Config.Session = *cfg.Session + } + + if cfg.Server != nil { + n.Config.Server, err = url.Parse(*cfg.Server) + if err != nil { + return fmt.Errorf("failed to parse server address: %w", err) + } + } + + if cfg.Ice != nil { + for _, server := range cfg.Ice.Servers { + iceServer := webrtc.ICEServer{ + URLs: server.URLs, + } + + if server.Username != nil && server.Password != nil { + iceServer.Username = *server.Username + iceServer.CredentialType = webrtc.ICECredentialTypePassword + iceServer.Credential = *server.Password + } + + n.Config.WebRTC.ICEServers = append(n.Config.WebRTC.ICEServers, iceServer) + } + } + + return nil +} + +func (n *Node) Check() error { + return nil +} + +func (n *Node) Prepare() error { + var err error + + n.PeerConnection, err = NewPeerConnection(n.config) + if err != nil { + return fmt.Errorf("failed to create peer connection: %w", err) + } + + return nil +} + +func (n *Node) Start() error { + return nil +} + +func (n *Node) Stop() error { + close(n.stop) + + return nil +} + +func (n *Node) Read() ([]byte, error) { + select { + case <-n.stop: + case b := <-n.receive: + return b, nil + } + + return nil, nil +} + +func (n *Node) Write(data []byte) error { + n.send <- data + + return nil +} + +func (n *Node) PollFDs() []int { + return []int{} +} + +func (n *Node) NetemFDs() []int { + return []int{} +} + +func (n *Node) Details() string { + details := map[string]string{ + "server": n.Config.Server.String(), + "session": n.Config.Session, + } + + kv := []string{} + for k, v := range details { + kv = append(kv, fmt.Sprintf("%s=%s", k, v)) + } + + return strings.Join(kv, ", ") +} + +func (n *Node) Close() error { + return nil +} + +func init() { + node.RegisterNode("webrtc", NewNode) +} diff --git a/lib/nodes/go/pkg/nodes/webrtc/types.go b/lib/nodes/go/pkg/nodes/webrtc/types.go new file mode 100644 index 000000000..3c8736831 --- /dev/null +++ b/lib/nodes/go/pkg/nodes/webrtc/types.go @@ -0,0 +1,37 @@ +package webrtc + +import ( + "encoding/json" + "time" + + "github.com/pion/webrtc/v3" +) + +type Connection struct { + ID int `json:"id"` + + Remote string `json:"remote"` + UserAgent string `json:"user_agent"` + Created time.Time `json:"created"` +} + +type ControlMessage struct { + ConnectionID int `json:"connection_id"` + Connections []Connection `json:"connections"` +} + +type Role struct { + Polite bool `json:"polite"` + First bool `json:"first"` +} + +type SignalingMessage struct { + Description *webrtc.SessionDescription `json:"description,omitempty"` + Candidate *webrtc.ICECandidate `json:"candidate,omitempty"` + Control *ControlMessage `json:"control,omitempty"` +} + +func (msg SignalingMessage) String() string { + b, _ := json.Marshal(msg) + return string(b) +} diff --git a/lib/nodes/go/pkg/nodes/webrtc/webrtc.go b/lib/nodes/go/pkg/nodes/webrtc/webrtc.go index 208366ea9..3cf6fc817 100644 --- a/lib/nodes/go/pkg/nodes/webrtc/webrtc.go +++ b/lib/nodes/go/pkg/nodes/webrtc/webrtc.go @@ -1,67 +1,309 @@ -package nodes +package webrtc import ( - "encoding/json" - "net/url" + "fmt" + "time" - node "git.rwth-aachen.de/acs/public/villas/node/pkg" + "github.com/pion/webrtc/v3" + "github.com/sirupsen/logrus" ) -type WebRTCNode struct { - node.Node +type PeerConnection struct { + *webrtc.PeerConnection + *SignalingClient - Config WebRTCConfig + config *Config + + makingOffer bool + ignoreOffer bool + + first bool + polite bool + + rollback bool } -type WebRTCConfig struct { - RendezvouzToken string `json:"token,omitempty"` - RendezvouzAddress url.URL `json:"address,omitempty"` +func NewPeerConnection(config *Config) (*PeerConnection, error) { + sc, err := NewSignalingClient(config.Server) + if err != nil { + return nil, fmt.Errorf("failed to create signaling client: %w", err) + } + + ppc := &PeerConnection{ + SignalingClient: sc, + config: config, + } + + ppc.SignalingClient.OnMessage(ppc.OnSignalingMessageHandler) + ppc.SignalingClient.OnConnect(ppc.OnSignalingConnectedHandler) + + if err := ppc.SignalingClient.ConnectWithBackoff(); err != nil { + return nil, fmt.Errorf("failed to connect signaling client: %w", err) + } + + return ppc, nil } -func NewWebRTCNode() node.Node { - return &WebRTCNode{} +func (pc *PeerConnection) createPeerConnection() (*webrtc.PeerConnection, error) { + logrus.Info("Created new peer connection") + + // Create a new RTCPeerConnection + ppc, err := webrtc.NewPeerConnection(pc.config.WebRTC) + if err != nil { + return nil, fmt.Errorf("failed to create peer connection: %w", err) + } + + // Set the handler for ICE connection state + // This will notify you when the peer has connected/disconnected + ppc.OnConnectionStateChange(pc.OnConnectionStateChangeHandler) + ppc.OnSignalingStateChange(pc.OnSignalingStateChangeHandler) + ppc.OnICECandidate(pc.OnICECandidateHandler) + ppc.OnNegotiationNeeded(pc.OnNegotiationNeededHandler) + ppc.OnDataChannel(pc.OnDataChannelHandler) + + if !pc.first { + dc, err := ppc.CreateDataChannel("demo", nil) + if err != nil { + logrus.Panicf("Failed to create datachannel: %s", err) + } + + close := make(chan struct{}) + + dc.OnClose(func() { pc.OnDataChannelCloseHandler(dc, close) }) + dc.OnOpen(func() { pc.OnDataChannelOpenHandler(dc, close) }) + dc.OnMessage(func(msg webrtc.DataChannelMessage) { pc.OnDataChannelMessageHandler(dc, &msg, close) }) + } + + return ppc, nil } -func (n *WebRTCNode) Parse(c []byte) error { - return json.Unmarshal(c, &n.Config) +func (pc *PeerConnection) rollbackPeerConnection() (*webrtc.PeerConnection, error) { + pc.rollback = true + defer func() { pc.rollback = false }() + + // Close previous peer connection in before creating a new one + // We need to do this as pion/webrtc currently does not support rollbacks + if err := pc.PeerConnection.Close(); err != nil { + return nil, fmt.Errorf("failed to close peer connection: %w", err) + } + + if ppc, err := pc.createPeerConnection(); err != nil { + return nil, err + } else { + return ppc, nil + } } -func (n *WebRTCNode) Check() error { +func (pc *PeerConnection) OnDataChannelOpenHandler(dc *webrtc.DataChannel, close chan struct{}) { + logrus.Infof("DataChannel opened: %s", dc.Label()) + + pc.SendMessages(dc, close) +} + +func (pc *PeerConnection) OnDataChannelCloseHandler(dc *webrtc.DataChannel, cl chan struct{}) { + logrus.Infof("DataChannel closed: %s", dc.Label()) + + close(cl) + + // We close the connection here to avoid waiting for the disconnected event + if err := pc.PeerConnection.Close(); err != nil { + logrus.Errorf("Failed to close peer connection: %s", err) + } +} + +func (pc *PeerConnection) OnDataChannelMessageHandler(dc *webrtc.DataChannel, msg *webrtc.DataChannelMessage, close chan struct{}) { + logrus.Infof("Received: %s", string(msg.Data)) +} + +func (pc *PeerConnection) SendMessages(dc *webrtc.DataChannel, close chan struct{}) { + logrus.Info("Start sending messages") + + i := 0 + t := time.NewTicker(1 * time.Second) + +loop: + for { + select { + case <-t.C: + msg := fmt.Sprintf("Hello %d", i) + + logrus.Infof("Send: %s", msg) + + if err := dc.SendText(msg); err != nil { + logrus.Errorf("Failed to send message: %s", err) + break loop + } + + case <-close: + break loop + } + + i++ + } + + logrus.Info("Stopped sending messages") +} + +func (pc *PeerConnection) OnDataChannelHandler(dc *webrtc.DataChannel) { + logrus.Infof("New DataChannel opened: %s", dc.Label()) + + close := make(chan struct{}) + + dc.OnOpen(func() { pc.OnDataChannelOpenHandler(dc, close) }) + dc.OnClose(func() { pc.OnDataChannelCloseHandler(dc, close) }) + dc.OnMessage(func(msg webrtc.DataChannelMessage) { pc.OnDataChannelMessageHandler(dc, &msg, close) }) +} + +func (pc *PeerConnection) OnICECandidateHandler(c *webrtc.ICECandidate) { + if c == nil { + logrus.Info("Candidate gathering concluded") + return + } + + logrus.Infof("Found new candidate: %s", c) + + if err := pc.SendSignalingMessage(&SignalingMessage{ + Candidate: c, + }); err != nil { + logrus.Errorf("Failed to send candidate: %s", err) + } +} + +func (pc *PeerConnection) OnNegotiationNeededHandler() { + logrus.Info("Negotation needed!") + + pc.makingOffer = true + + offer, err := pc.CreateOffer(nil) + if err != nil { + logrus.Panicf("Failed to create offer: %s", err) + } + + if err := pc.SetLocalDescription(offer); err != nil { + logrus.Panicf("Failed to set local description: %s", err) + } + + if err := pc.SendSignalingMessage(&SignalingMessage{ + Description: &offer, + }); err != nil { + logrus.Panicf("Failed to send offer: %s", err) + } + + pc.makingOffer = false +} + +func (pc *PeerConnection) OnSignalingStateChangeHandler(ss webrtc.SignalingState) { + logrus.Infof("Signaling State has changed: %s", ss.String()) +} + +func (pc *PeerConnection) OnConnectionStateChangeHandler(pcs webrtc.PeerConnectionState) { + logrus.Infof("Connection State has changed: %s", pcs.String()) + + switch pcs { + case webrtc.PeerConnectionStateFailed: + fallthrough + case webrtc.PeerConnectionStateDisconnected: + logrus.Info("Closing peer connection") + + if err := pc.PeerConnection.Close(); err != nil { + logrus.Panicf("Failed to close peer connection: %s", err) + } + + case webrtc.PeerConnectionStateClosed: + if pc.rollback { + return + } + + logrus.Info("Closed peer connection") + + var err error + pc.PeerConnection, err = pc.createPeerConnection() + if err != nil { + logrus.Panicf("Failed to set re-create peer connection: %s", err) + } + } +} + +func (pc *PeerConnection) OnSignalingConnectedHandler() { + var err error + + logrus.Info("Signaling connected") + + // Create initial peer connection + if pc.PeerConnection == nil { + if pc.PeerConnection, err = pc.createPeerConnection(); err != nil { + logrus.Warnf("failed to create peer connection: %s", err) + } + } +} + +func (pc *PeerConnection) OnSignalingMessageHandler(msg *SignalingMessage) { + var err error + + if msg.Control != nil { + if len(msg.Control.Connections) > 2 { + logrus.Panicf("There are already two peers connected to this session.") + } + + pc.first = true + for _, c := range msg.Control.Connections { + if c.ID < msg.Control.ConnectionID { + pc.first = false + } + } + + pc.polite = pc.first + + logrus.Infof("New role: polite=%v, first=%v", pc.polite, pc.first) + } else if msg.Description != nil { + readyForOffer := !pc.makingOffer && pc.SignalingState() == webrtc.SignalingStateStable + offerCollision := msg.Description.Type == webrtc.SDPTypeOffer && !readyForOffer + + pc.ignoreOffer = !pc.polite && offerCollision + if pc.ignoreOffer { + return + } + + if msg.Description.Type == webrtc.SDPTypeOffer && pc.PeerConnection.SignalingState() != webrtc.SignalingStateStable { + pc.PeerConnection, err = pc.rollbackPeerConnection() + if err != nil { + logrus.Panicf("Failed to rollback peer connection: %s", err) + } + } + + if err := pc.PeerConnection.SetRemoteDescription(*msg.Description); err != nil { + logrus.Panicf("Failed to set remote description: %s", err) + } + + if msg.Description.Type == webrtc.SDPTypeOffer { + answer, err := pc.PeerConnection.CreateAnswer(nil) + if err != nil { + logrus.Panicf("Failed to create answer: %s", err) + } + + if err := pc.SetLocalDescription(answer); err != nil { + logrus.Panicf("Failed to rollback signaling state: %s", err) + } + + pc.SendSignalingMessage(&SignalingMessage{ + Description: pc.LocalDescription(), + }) + } + } else if msg.Candidate != nil { + if err := pc.AddICECandidate(msg.Candidate.ToJSON()); err != nil && !pc.ignoreOffer { + logrus.Panicf("Failed to add new ICE candidate: %s", err) + } + } +} + +func (pc *PeerConnection) Close() error { + if err := pc.SignalingClient.Close(); err != nil { + return fmt.Errorf("failed to close signaling client: %w", err) + } + + if err := pc.PeerConnection.Close(); err != nil { + return fmt.Errorf("failed to close peer connection: %w", err) + } + return nil } - -func (n *WebRTCNode) Prepare() error { - return nil -} - -func (n *WebRTCNode) Start() error { - return nil -} - -func (n *WebRTCNode) Stop() error { - return nil -} - -func (n *WebRTCNode) Read() ([]byte, error) { - return nil, nil -} - -func (n *WebRTCNode) Write(data []byte) error { - return nil -} - -func (n *WebRTCNode) PollFDs() []int { - return nil -} - -func (n *WebRTCNode) NetemFDs() []int { - return nil -} - -func (n *WebRTCNode) Details() string { - return "this-is-my-webrtc-node" -} - -func init() { - node.RegisterNode("webrtc", NewWebRTCNode) -}