77 "time"
88
99 "github.com/google/uuid"
10+ "github.com/rs/zerolog"
1011)
1112
1213const (
@@ -17,7 +18,7 @@ func SessionIdleErr(timeout time.Duration) error {
1718 return fmt .Errorf ("session idle for %v" , timeout )
1819}
1920
20- // Each Session is a bidirectional pipe of datagrams between transport and dstConn
21+ // Session is a bidirectional pipe of datagrams between transport and dstConn
2122// Currently the only implementation of transport is quic DatagramMuxer
2223// Destination can be a connection with origin or with eyeball
2324// When the destination is origin:
@@ -35,9 +36,10 @@ type Session struct {
3536 // activeAtChan is used to communicate the last read/write time
3637 activeAtChan chan time.Time
3738 closeChan chan error
39+ log * zerolog.Logger
3840}
3941
40- func newSession (id uuid.UUID , transport transport , dstConn io.ReadWriteCloser ) * Session {
42+ func newSession (id uuid.UUID , transport transport , dstConn io.ReadWriteCloser , log * zerolog. Logger ) * Session {
4143 return & Session {
4244 ID : id ,
4345 transport : transport ,
@@ -47,14 +49,16 @@ func newSession(id uuid.UUID, transport transport, dstConn io.ReadWriteCloser) *
4749 activeAtChan : make (chan time.Time , 2 ),
4850 // capacity is 2 because close() and dstToTransport routine in Serve() can write to this channel
4951 closeChan : make (chan error , 2 ),
52+ log : log ,
5053 }
5154}
5255
5356func (s * Session ) Serve (ctx context.Context , closeAfterIdle time.Duration ) (closedByRemote bool , err error ) {
5457 go func () {
5558 // QUIC implementation copies data to another buffer before returning https://github.com/lucas-clemente/quic-go/blob/v0.24.0/session.go#L1967-L1975
5659 // This makes it safe to share readBuffer between iterations
57- readBuffer := make ([]byte , s .transport .ReceiveMTU ())
60+ const maxPacketSize = 1500
61+ readBuffer := make ([]byte , maxPacketSize )
5862 for {
5963 if err := s .dstToTransport (readBuffer ); err != nil {
6064 s .closeChan <- err
@@ -103,8 +107,15 @@ func (s *Session) dstToTransport(buffer []byte) error {
103107 n , err := s .dstConn .Read (buffer )
104108 s .markActive ()
105109 if n > 0 {
106- if err := s .transport .SendTo (s .ID , buffer [:n ]); err != nil {
107- return err
110+ if n <= int (s .transport .MTU ()) {
111+ err = s .transport .SendTo (s .ID , buffer [:n ])
112+ } else {
113+ // drop packet for now, eventually reply with ICMP for PMTUD
114+ s .log .Debug ().
115+ Str ("session" , s .ID .String ()).
116+ Int ("len" , n ).
117+ Uint ("mtu" , s .transport .MTU ()).
118+ Msg ("dropped packet exceeding MTU" )
108119 }
109120 }
110121 return err
0 commit comments