@@ -2,6 +2,7 @@ package socket
22
33import (
44 "bytes"
5+ "context"
56 "crypto/rand"
67 "encoding/base32"
78 "encoding/gob"
@@ -178,6 +179,48 @@ func (s *QUICSocket) WaitForDialIn() (*snet.UDPAddr, error) {
178179 return & addr , nil
179180}
180181
182+ func (s * QUICSocket ) WaitForDialInWithContext (ctx context.Context ) (* snet.UDPAddr , error ) {
183+ bts := make ([]byte , packets .PACKET_SIZE )
184+ log .Debugf ("Wait for Dial In" )
185+ stream , err := s .listenConns [0 ].AcceptStreamWithContext (ctx )
186+ if err != nil {
187+ return nil , err
188+ }
189+
190+ s .listenConns [0 ].SetStream (stream )
191+
192+ select {
193+ case s .listenConns [0 ].Ready <- true :
194+ default :
195+ }
196+
197+ _ , err = stream .Read (bts )
198+ if err != nil {
199+ return nil , err
200+ }
201+ p := DialPacketQuic {}
202+ network := bytes .NewBuffer (bts ) // Stand-in for a network connection
203+ dec := gob .NewDecoder (network )
204+ err = dec .Decode (& p )
205+ if err != nil {
206+ return nil , err
207+ }
208+
209+ s .listenConns [0 ].SetRemote (& p .Addr )
210+ log .Debugf ("Waiting for %d more connections" , p .NumPaths - 1 )
211+
212+ for i := 1 ; i < p .NumPaths ; i ++ {
213+ _ , err := s .WaitForIncomingConn ()
214+ if err != nil {
215+ return nil , err
216+ }
217+ log .Debugf ("Dialed In %d of %d" , i , p .NumPaths )
218+ }
219+
220+ addr := p .Addr
221+ return & addr , nil
222+ }
223+
181224func (s * QUICSocket ) Dial (remote snet.UDPAddr , path snet.Path , options DialOptions , i int ) (packets.UDPConn , error ) {
182225 // appnet.SetPath(&remote, path)
183226 if s .options == nil || ! s .options .MultiportMode {
0 commit comments