2015-06-24 12:39:46 +01:00
|
|
|
// Copyright (C) 2015 Audrius Butkevicius and Contributors (see the CONTRIBUTORS file).
|
|
|
|
|
|
2025-08-24 14:17:20 +02:00
|
|
|
//go:generate go tool genxdr -o packets_xdr.go packets.go
|
2015-06-24 12:39:46 +01:00
|
|
|
|
|
|
|
|
package protocol
|
|
|
|
|
|
2015-07-17 20:17:49 +01:00
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"net"
|
2015-09-02 21:35:52 +01:00
|
|
|
|
2024-12-01 16:50:17 +01:00
|
|
|
"github.com/syncthing/syncthing/lib/protocol"
|
2015-07-17 20:17:49 +01:00
|
|
|
)
|
|
|
|
|
|
2015-06-24 12:39:46 +01:00
|
|
|
const (
|
2015-06-28 01:52:01 +01:00
|
|
|
messageTypePing int32 = iota
|
|
|
|
|
messageTypePong
|
|
|
|
|
messageTypeJoinRelayRequest
|
|
|
|
|
messageTypeJoinSessionRequest
|
|
|
|
|
messageTypeResponse
|
|
|
|
|
messageTypeConnectRequest
|
|
|
|
|
messageTypeSessionInvitation
|
2015-11-20 23:42:49 +00:00
|
|
|
messageTypeRelayFull
|
2015-06-24 12:39:46 +01:00
|
|
|
)
|
|
|
|
|
|
2015-06-28 01:52:01 +01:00
|
|
|
type header struct {
|
|
|
|
|
magic uint32
|
|
|
|
|
messageType int32
|
|
|
|
|
messageLength int32
|
2015-06-24 12:39:46 +01:00
|
|
|
}
|
|
|
|
|
|
2024-11-19 11:32:56 +01:00
|
|
|
type (
|
|
|
|
|
Ping struct{}
|
|
|
|
|
Pong struct{}
|
|
|
|
|
RelayFull struct{}
|
|
|
|
|
)
|
2015-06-28 01:52:01 +01:00
|
|
|
|
2022-10-01 21:41:02 +02:00
|
|
|
type JoinRelayRequest struct {
|
|
|
|
|
Token string
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-28 01:52:01 +01:00
|
|
|
type JoinSessionRequest struct {
|
|
|
|
|
Key []byte // max:32
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Response struct {
|
|
|
|
|
Code int32
|
|
|
|
|
Message string
|
|
|
|
|
}
|
2015-06-24 12:39:46 +01:00
|
|
|
|
|
|
|
|
type ConnectRequest struct {
|
|
|
|
|
ID []byte // max:32
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type SessionInvitation struct {
|
2015-06-28 01:52:01 +01:00
|
|
|
From []byte // max:32
|
2015-06-24 12:39:46 +01:00
|
|
|
Key []byte // max:32
|
|
|
|
|
Address []byte // max:32
|
|
|
|
|
Port uint16
|
|
|
|
|
ServerSocket bool
|
|
|
|
|
}
|
2015-07-17 20:17:49 +01:00
|
|
|
|
2015-07-17 21:49:45 +01:00
|
|
|
func (i SessionInvitation) String() string {
|
2020-06-07 10:31:12 +02:00
|
|
|
device := "<invalid>"
|
2024-12-01 16:50:17 +01:00
|
|
|
if address, err := protocol.DeviceIDFromBytes(i.From); err == nil {
|
2020-06-07 10:31:12 +02:00
|
|
|
device = address.String()
|
|
|
|
|
}
|
2021-09-05 17:20:52 +02:00
|
|
|
return fmt.Sprintf("%s@%s:%d", device, net.IP(i.Address), i.Port)
|
2015-07-17 20:17:49 +01:00
|
|
|
}
|
|
|
|
|
|
2015-07-17 21:49:45 +01:00
|
|
|
func (i SessionInvitation) GoString() string {
|
|
|
|
|
return i.String()
|
|
|
|
|
}
|