2015-06-24 11:39:46 +00:00
|
|
|
// Copyright (C) 2015 Audrius Butkevicius and Contributors (see the CONTRIBUTORS file).
|
|
|
|
|
2016-03-09 12:43:16 +00:00
|
|
|
//go:generate -command genxdr go run ../../../vendor/github.com/calmh/xdr/cmd/genxdr/main.go
|
2015-06-24 11:39:46 +00:00
|
|
|
//go:generate genxdr -o packets_xdr.go packets.go
|
|
|
|
|
|
|
|
package protocol
|
|
|
|
|
2015-07-17 19:17:49 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net"
|
2015-09-02 20:35:52 +00:00
|
|
|
|
2015-09-22 17:38:46 +00:00
|
|
|
syncthingprotocol "github.com/syncthing/syncthing/lib/protocol"
|
2015-07-17 19:17:49 +00:00
|
|
|
)
|
|
|
|
|
2015-06-24 11:39:46 +00:00
|
|
|
const (
|
2015-06-28 00:52:01 +00:00
|
|
|
messageTypePing int32 = iota
|
|
|
|
messageTypePong
|
|
|
|
messageTypeJoinRelayRequest
|
|
|
|
messageTypeJoinSessionRequest
|
|
|
|
messageTypeResponse
|
|
|
|
messageTypeConnectRequest
|
|
|
|
messageTypeSessionInvitation
|
2015-11-20 23:42:49 +00:00
|
|
|
messageTypeRelayFull
|
2015-06-24 11:39:46 +00:00
|
|
|
)
|
|
|
|
|
2015-06-28 00:52:01 +00:00
|
|
|
type header struct {
|
|
|
|
magic uint32
|
|
|
|
messageType int32
|
|
|
|
messageLength int32
|
2015-06-24 11:39:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Ping struct{}
|
|
|
|
type Pong struct{}
|
2015-06-28 00:52:01 +00:00
|
|
|
type JoinRelayRequest struct{}
|
2015-11-20 23:42:49 +00:00
|
|
|
type RelayFull struct{}
|
2015-06-28 00:52:01 +00:00
|
|
|
|
|
|
|
type JoinSessionRequest struct {
|
|
|
|
Key []byte // max:32
|
|
|
|
}
|
|
|
|
|
|
|
|
type Response struct {
|
|
|
|
Code int32
|
|
|
|
Message string
|
|
|
|
}
|
2015-06-24 11:39:46 +00:00
|
|
|
|
|
|
|
type ConnectRequest struct {
|
|
|
|
ID []byte // max:32
|
|
|
|
}
|
|
|
|
|
|
|
|
type SessionInvitation struct {
|
2015-06-28 00:52:01 +00:00
|
|
|
From []byte // max:32
|
2015-06-24 11:39:46 +00:00
|
|
|
Key []byte // max:32
|
|
|
|
Address []byte // max:32
|
|
|
|
Port uint16
|
|
|
|
ServerSocket bool
|
|
|
|
}
|
2015-07-17 19:17:49 +00:00
|
|
|
|
2015-07-17 20:49:45 +00:00
|
|
|
func (i SessionInvitation) String() string {
|
2015-07-17 19:17:49 +00:00
|
|
|
return fmt.Sprintf("%s@%s", syncthingprotocol.DeviceIDFromBytes(i.From), i.AddressString())
|
|
|
|
}
|
|
|
|
|
2015-07-17 20:49:45 +00:00
|
|
|
func (i SessionInvitation) GoString() string {
|
|
|
|
return i.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i SessionInvitation) AddressString() string {
|
2015-07-17 19:17:49 +00:00
|
|
|
return fmt.Sprintf("%s:%d", net.IP(i.Address), i.Port)
|
|
|
|
}
|