mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-05 21:27:35 +03:00
test version negotiation packet
This commit is contained in:
parent
bb3c8b707b
commit
fd28921bdd
2 changed files with 29 additions and 11 deletions
23
server.go
23
server.go
|
@ -68,11 +68,13 @@ func (s *Server) ListenAndServe(address string) error {
|
|||
continue
|
||||
}
|
||||
|
||||
fmt.Printf("<- Got packet %d (%d bytes) from %v\n", publicHeader.PacketNumber, n, remoteAddr)
|
||||
// fmt.Printf("<- Got packet %d (%d bytes) from %v\n", publicHeader.PacketNumber, n, remoteAddr)
|
||||
|
||||
// Send Version Negotiation Packet if the client is speaking a different protocol version
|
||||
if publicHeader.VersionFlag && !protocol.IsSupportedVersion(publicHeader.VersionNumber) {
|
||||
if err := sendVersionNegotiation(conn, remoteAddr, publicHeader); err != nil {
|
||||
fmt.Println("Sending VersionNegotiationPacket")
|
||||
_, err = conn.WriteToUDP(composeVersionNegotiation(publicHeader.ConnectionID), remoteAddr)
|
||||
if err != nil {
|
||||
fmt.Printf("Error sending version negotiation: %s", err.Error())
|
||||
}
|
||||
continue
|
||||
|
@ -91,18 +93,17 @@ func (s *Server) ListenAndServe(address string) error {
|
|||
}
|
||||
}
|
||||
|
||||
func sendVersionNegotiation(conn *net.UDPConn, remoteAddr *net.UDPAddr, publicHeader *PublicHeader) error {
|
||||
fmt.Println("Sending VersionNegotiationPacket")
|
||||
func composeVersionNegotiation(connectionID protocol.ConnectionID) []byte {
|
||||
fullReply := &bytes.Buffer{}
|
||||
responsePublicHeader := PublicHeader{ConnectionID: publicHeader.ConnectionID, PacketNumber: 1, VersionFlag: true}
|
||||
responsePublicHeader := PublicHeader{
|
||||
ConnectionID: connectionID,
|
||||
PacketNumber: 1,
|
||||
VersionFlag: true,
|
||||
}
|
||||
err := responsePublicHeader.WritePublicHeader(fullReply)
|
||||
if err != nil {
|
||||
return err
|
||||
panic(err) // Should not happen ;)
|
||||
}
|
||||
fullReply.Write(protocol.SupportedVersionsAsTags)
|
||||
_, err = conn.WriteToUDP(fullReply.Bytes(), remoteAddr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return fullReply.Bytes()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue