forked from quic-go/quic-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_session.go
59 lines (46 loc) · 1.34 KB
/
server_session.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package quic
import (
"fmt"
"github.com/boisjacques/qed/internal/protocol"
"github.com/boisjacques/qed/internal/utils"
)
type serverSession struct {
quicSession
config *Config
logger utils.Logger
}
var _ packetHandler = &serverSession{}
func newServerSession(sess quicSession, config *Config, logger utils.Logger) packetHandler {
return &serverSession{
quicSession: sess,
config: config,
logger: logger,
}
}
func (s *serverSession) handlePacket(p *receivedPacket) {
if err := s.handlePacketImpl(p); err != nil {
s.logger.Debugf("error handling packet from %s: %s", p.remoteAddr, err)
}
}
func (s *serverSession) handlePacketImpl(p *receivedPacket) error {
hdr := p.header
// Probably an old packet that was sent by the client before the version was negotiated.
// It is safe to drop it.
if hdr.IsLongHeader && hdr.Version != s.quicSession.GetVersion() {
return nil
}
if hdr.IsLongHeader {
switch hdr.Type {
case protocol.PacketTypeInitial, protocol.PacketTypeHandshake:
// nothing to do here. Packet will be passed to the session.
default:
// Note that this also drops 0-RTT packets.
return fmt.Errorf("Received unsupported packet type: %s", hdr.Type)
}
}
s.quicSession.handlePacket(p)
return nil
}
func (s *serverSession) GetPerspective() protocol.Perspective {
return protocol.PerspectiveServer
}