mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-09 14:50:56 +00:00
34c04babbe
1. Change listen addresses to URIs 2. Break out connectionSvc to support listeners and dialers based on schema 3. Add relay announcement and lookups part of discovery service
385 lines
10 KiB
Go
385 lines
10 KiB
Go
// ************************************************************
|
|
// This file is automatically generated by genxdr. Do not edit.
|
|
// ************************************************************
|
|
|
|
package discover
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
|
|
"github.com/calmh/xdr"
|
|
)
|
|
|
|
/*
|
|
|
|
Query Structure:
|
|
|
|
0 1 2 3
|
|
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
| Magic |
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
| Length of Device ID |
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
/ /
|
|
\ Device ID (variable length) \
|
|
/ /
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
|
|
struct Query {
|
|
unsigned int Magic;
|
|
opaque DeviceID<32>;
|
|
}
|
|
|
|
*/
|
|
|
|
func (o Query) EncodeXDR(w io.Writer) (int, error) {
|
|
var xw = xdr.NewWriter(w)
|
|
return o.EncodeXDRInto(xw)
|
|
}
|
|
|
|
func (o Query) MarshalXDR() ([]byte, error) {
|
|
return o.AppendXDR(make([]byte, 0, 128))
|
|
}
|
|
|
|
func (o Query) MustMarshalXDR() []byte {
|
|
bs, err := o.MarshalXDR()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return bs
|
|
}
|
|
|
|
func (o Query) AppendXDR(bs []byte) ([]byte, error) {
|
|
var aw = xdr.AppendWriter(bs)
|
|
var xw = xdr.NewWriter(&aw)
|
|
_, err := o.EncodeXDRInto(xw)
|
|
return []byte(aw), err
|
|
}
|
|
|
|
func (o Query) EncodeXDRInto(xw *xdr.Writer) (int, error) {
|
|
xw.WriteUint32(o.Magic)
|
|
if l := len(o.DeviceID); l > 32 {
|
|
return xw.Tot(), xdr.ElementSizeExceeded("DeviceID", l, 32)
|
|
}
|
|
xw.WriteBytes(o.DeviceID)
|
|
return xw.Tot(), xw.Error()
|
|
}
|
|
|
|
func (o *Query) DecodeXDR(r io.Reader) error {
|
|
xr := xdr.NewReader(r)
|
|
return o.DecodeXDRFrom(xr)
|
|
}
|
|
|
|
func (o *Query) UnmarshalXDR(bs []byte) error {
|
|
var br = bytes.NewReader(bs)
|
|
var xr = xdr.NewReader(br)
|
|
return o.DecodeXDRFrom(xr)
|
|
}
|
|
|
|
func (o *Query) DecodeXDRFrom(xr *xdr.Reader) error {
|
|
o.Magic = xr.ReadUint32()
|
|
o.DeviceID = xr.ReadBytesMax(32)
|
|
return xr.Error()
|
|
}
|
|
|
|
/*
|
|
|
|
Announce Structure:
|
|
|
|
0 1 2 3
|
|
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
| Magic |
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
/ /
|
|
\ Device Structure \
|
|
/ /
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
| Number of Extra |
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
/ /
|
|
\ Zero or more Device Structures \
|
|
/ /
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
|
|
struct Announce {
|
|
unsigned int Magic;
|
|
Device This;
|
|
Device Extra<16>;
|
|
}
|
|
|
|
*/
|
|
|
|
func (o Announce) EncodeXDR(w io.Writer) (int, error) {
|
|
var xw = xdr.NewWriter(w)
|
|
return o.EncodeXDRInto(xw)
|
|
}
|
|
|
|
func (o Announce) MarshalXDR() ([]byte, error) {
|
|
return o.AppendXDR(make([]byte, 0, 128))
|
|
}
|
|
|
|
func (o Announce) MustMarshalXDR() []byte {
|
|
bs, err := o.MarshalXDR()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return bs
|
|
}
|
|
|
|
func (o Announce) AppendXDR(bs []byte) ([]byte, error) {
|
|
var aw = xdr.AppendWriter(bs)
|
|
var xw = xdr.NewWriter(&aw)
|
|
_, err := o.EncodeXDRInto(xw)
|
|
return []byte(aw), err
|
|
}
|
|
|
|
func (o Announce) EncodeXDRInto(xw *xdr.Writer) (int, error) {
|
|
xw.WriteUint32(o.Magic)
|
|
_, err := o.This.EncodeXDRInto(xw)
|
|
if err != nil {
|
|
return xw.Tot(), err
|
|
}
|
|
if l := len(o.Extra); l > 16 {
|
|
return xw.Tot(), xdr.ElementSizeExceeded("Extra", l, 16)
|
|
}
|
|
xw.WriteUint32(uint32(len(o.Extra)))
|
|
for i := range o.Extra {
|
|
_, err := o.Extra[i].EncodeXDRInto(xw)
|
|
if err != nil {
|
|
return xw.Tot(), err
|
|
}
|
|
}
|
|
return xw.Tot(), xw.Error()
|
|
}
|
|
|
|
func (o *Announce) DecodeXDR(r io.Reader) error {
|
|
xr := xdr.NewReader(r)
|
|
return o.DecodeXDRFrom(xr)
|
|
}
|
|
|
|
func (o *Announce) UnmarshalXDR(bs []byte) error {
|
|
var br = bytes.NewReader(bs)
|
|
var xr = xdr.NewReader(br)
|
|
return o.DecodeXDRFrom(xr)
|
|
}
|
|
|
|
func (o *Announce) DecodeXDRFrom(xr *xdr.Reader) error {
|
|
o.Magic = xr.ReadUint32()
|
|
(&o.This).DecodeXDRFrom(xr)
|
|
_ExtraSize := int(xr.ReadUint32())
|
|
if _ExtraSize < 0 {
|
|
return xdr.ElementSizeExceeded("Extra", _ExtraSize, 16)
|
|
}
|
|
if _ExtraSize > 16 {
|
|
return xdr.ElementSizeExceeded("Extra", _ExtraSize, 16)
|
|
}
|
|
o.Extra = make([]Device, _ExtraSize)
|
|
for i := range o.Extra {
|
|
(&o.Extra[i]).DecodeXDRFrom(xr)
|
|
}
|
|
return xr.Error()
|
|
}
|
|
|
|
/*
|
|
|
|
Relay Structure:
|
|
|
|
0 1 2 3
|
|
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
| Length of Address |
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
/ /
|
|
\ Address (variable length) \
|
|
/ /
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
| Latency |
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
|
|
struct Relay {
|
|
string Address<256>;
|
|
int Latency;
|
|
}
|
|
|
|
*/
|
|
|
|
func (o Relay) EncodeXDR(w io.Writer) (int, error) {
|
|
var xw = xdr.NewWriter(w)
|
|
return o.EncodeXDRInto(xw)
|
|
}
|
|
|
|
func (o Relay) MarshalXDR() ([]byte, error) {
|
|
return o.AppendXDR(make([]byte, 0, 128))
|
|
}
|
|
|
|
func (o Relay) MustMarshalXDR() []byte {
|
|
bs, err := o.MarshalXDR()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return bs
|
|
}
|
|
|
|
func (o Relay) AppendXDR(bs []byte) ([]byte, error) {
|
|
var aw = xdr.AppendWriter(bs)
|
|
var xw = xdr.NewWriter(&aw)
|
|
_, err := o.EncodeXDRInto(xw)
|
|
return []byte(aw), err
|
|
}
|
|
|
|
func (o Relay) EncodeXDRInto(xw *xdr.Writer) (int, error) {
|
|
if l := len(o.Address); l > 256 {
|
|
return xw.Tot(), xdr.ElementSizeExceeded("Address", l, 256)
|
|
}
|
|
xw.WriteString(o.Address)
|
|
xw.WriteUint32(uint32(o.Latency))
|
|
return xw.Tot(), xw.Error()
|
|
}
|
|
|
|
func (o *Relay) DecodeXDR(r io.Reader) error {
|
|
xr := xdr.NewReader(r)
|
|
return o.DecodeXDRFrom(xr)
|
|
}
|
|
|
|
func (o *Relay) UnmarshalXDR(bs []byte) error {
|
|
var br = bytes.NewReader(bs)
|
|
var xr = xdr.NewReader(br)
|
|
return o.DecodeXDRFrom(xr)
|
|
}
|
|
|
|
func (o *Relay) DecodeXDRFrom(xr *xdr.Reader) error {
|
|
o.Address = xr.ReadStringMax(256)
|
|
o.Latency = int32(xr.ReadUint32())
|
|
return xr.Error()
|
|
}
|
|
|
|
/*
|
|
|
|
Device Structure:
|
|
|
|
0 1 2 3
|
|
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
| Length of ID |
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
/ /
|
|
\ ID (variable length) \
|
|
/ /
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
| Number of Addresses |
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
| Length of Addresses |
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
/ /
|
|
\ Addresses (variable length) \
|
|
/ /
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
| Number of Relays |
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
/ /
|
|
\ Zero or more Relay Structures \
|
|
/ /
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
|
|
struct Device {
|
|
opaque ID<32>;
|
|
string Addresses<16>;
|
|
Relay Relays<16>;
|
|
}
|
|
|
|
*/
|
|
|
|
func (o Device) EncodeXDR(w io.Writer) (int, error) {
|
|
var xw = xdr.NewWriter(w)
|
|
return o.EncodeXDRInto(xw)
|
|
}
|
|
|
|
func (o Device) MarshalXDR() ([]byte, error) {
|
|
return o.AppendXDR(make([]byte, 0, 128))
|
|
}
|
|
|
|
func (o Device) MustMarshalXDR() []byte {
|
|
bs, err := o.MarshalXDR()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return bs
|
|
}
|
|
|
|
func (o Device) AppendXDR(bs []byte) ([]byte, error) {
|
|
var aw = xdr.AppendWriter(bs)
|
|
var xw = xdr.NewWriter(&aw)
|
|
_, err := o.EncodeXDRInto(xw)
|
|
return []byte(aw), err
|
|
}
|
|
|
|
func (o Device) EncodeXDRInto(xw *xdr.Writer) (int, error) {
|
|
if l := len(o.ID); l > 32 {
|
|
return xw.Tot(), xdr.ElementSizeExceeded("ID", l, 32)
|
|
}
|
|
xw.WriteBytes(o.ID)
|
|
if l := len(o.Addresses); l > 16 {
|
|
return xw.Tot(), xdr.ElementSizeExceeded("Addresses", l, 16)
|
|
}
|
|
xw.WriteUint32(uint32(len(o.Addresses)))
|
|
for i := range o.Addresses {
|
|
xw.WriteString(o.Addresses[i])
|
|
}
|
|
if l := len(o.Relays); l > 16 {
|
|
return xw.Tot(), xdr.ElementSizeExceeded("Relays", l, 16)
|
|
}
|
|
xw.WriteUint32(uint32(len(o.Relays)))
|
|
for i := range o.Relays {
|
|
_, err := o.Relays[i].EncodeXDRInto(xw)
|
|
if err != nil {
|
|
return xw.Tot(), err
|
|
}
|
|
}
|
|
return xw.Tot(), xw.Error()
|
|
}
|
|
|
|
func (o *Device) DecodeXDR(r io.Reader) error {
|
|
xr := xdr.NewReader(r)
|
|
return o.DecodeXDRFrom(xr)
|
|
}
|
|
|
|
func (o *Device) UnmarshalXDR(bs []byte) error {
|
|
var br = bytes.NewReader(bs)
|
|
var xr = xdr.NewReader(br)
|
|
return o.DecodeXDRFrom(xr)
|
|
}
|
|
|
|
func (o *Device) DecodeXDRFrom(xr *xdr.Reader) error {
|
|
o.ID = xr.ReadBytesMax(32)
|
|
_AddressesSize := int(xr.ReadUint32())
|
|
if _AddressesSize < 0 {
|
|
return xdr.ElementSizeExceeded("Addresses", _AddressesSize, 16)
|
|
}
|
|
if _AddressesSize > 16 {
|
|
return xdr.ElementSizeExceeded("Addresses", _AddressesSize, 16)
|
|
}
|
|
o.Addresses = make([]string, _AddressesSize)
|
|
for i := range o.Addresses {
|
|
o.Addresses[i] = xr.ReadString()
|
|
}
|
|
_RelaysSize := int(xr.ReadUint32())
|
|
if _RelaysSize < 0 {
|
|
return xdr.ElementSizeExceeded("Relays", _RelaysSize, 16)
|
|
}
|
|
if _RelaysSize > 16 {
|
|
return xdr.ElementSizeExceeded("Relays", _RelaysSize, 16)
|
|
}
|
|
o.Relays = make([]Relay, _RelaysSize)
|
|
for i := range o.Relays {
|
|
(&o.Relays[i]).DecodeXDRFrom(xr)
|
|
}
|
|
return xr.Error()
|
|
}
|