mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-09 14:50:56 +00:00
New port number for new format global discovery
This commit is contained in:
parent
864bb8bc34
commit
b7cf8a471f
@ -144,7 +144,7 @@ type NodeConfiguration struct {
|
||||
|
||||
type OptionsConfiguration struct {
|
||||
ListenAddress []string `xml:"listenAddress" default:"0.0.0.0:22000"`
|
||||
GlobalAnnServer string `xml:"globalAnnounceServer" default:"announce.syncthing.net:22025"`
|
||||
GlobalAnnServer string `xml:"globalAnnounceServer" default:"announce.syncthing.net:22026"`
|
||||
GlobalAnnEnabled bool `xml:"globalAnnounceEnabled" default:"true"`
|
||||
LocalAnnEnabled bool `xml:"localAnnounceEnabled" default:"true"`
|
||||
LocalAnnPort int `xml:"localAnnouncePort" default:"21025"`
|
||||
@ -362,6 +362,12 @@ func Load(rd io.Reader, myID protocol.NodeID) (Configuration, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// The global discovery format and port number changed in v0.9. Having the
|
||||
// default announce server but old port number is guaranteed to be legacy.
|
||||
if cfg.Options.GlobalAnnServer == "announce.syncthing.net:22025" {
|
||||
cfg.Options.GlobalAnnServer = "announce.syncthing.net:22026"
|
||||
}
|
||||
|
||||
return cfg, err
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ func main() {
|
||||
var statsIntv int
|
||||
var statsFile string
|
||||
|
||||
flag.StringVar(&listen, "listen", ":22025", "Listen address")
|
||||
flag.StringVar(&listen, "listen", ":22026", "Listen address")
|
||||
flag.BoolVar(&debug, "debug", false, "Enable debug output")
|
||||
flag.BoolVar(×tamp, "timestamp", true, "Timestamp the log output")
|
||||
flag.IntVar(&statsIntv, "stats-intv", 0, "Statistics output interval (s)")
|
||||
@ -103,10 +103,10 @@ func main() {
|
||||
magic := binary.BigEndian.Uint32(buf)
|
||||
|
||||
switch magic {
|
||||
case discover.AnnouncementMagicV2:
|
||||
case discover.AnnouncementMagic:
|
||||
handleAnnounceV2(addr, buf)
|
||||
|
||||
case discover.QueryMagicV2:
|
||||
case discover.QueryMagic:
|
||||
handleQueryV2(conn, addr, buf)
|
||||
|
||||
default:
|
||||
@ -146,7 +146,7 @@ func limit(addr *net.UDPAddr) bool {
|
||||
}
|
||||
|
||||
func handleAnnounceV2(addr *net.UDPAddr, buf []byte) {
|
||||
var pkt discover.AnnounceV2
|
||||
var pkt discover.Announce
|
||||
err := pkt.UnmarshalXDR(buf)
|
||||
if err != nil && err != io.EOF {
|
||||
log.Println("AnnounceV2 Unmarshal:", err)
|
||||
@ -197,7 +197,7 @@ func handleAnnounceV2(addr *net.UDPAddr, buf []byte) {
|
||||
}
|
||||
|
||||
func handleQueryV2(conn *net.UDPConn, addr *net.UDPAddr, buf []byte) {
|
||||
var pkt discover.QueryV2
|
||||
var pkt discover.Query
|
||||
err := pkt.UnmarshalXDR(buf)
|
||||
if err != nil {
|
||||
log.Println("QueryV2 Unmarshal:", err)
|
||||
@ -222,8 +222,8 @@ func handleQueryV2(conn *net.UDPConn, addr *net.UDPAddr, buf []byte) {
|
||||
lock.Unlock()
|
||||
|
||||
if ok && len(node.addresses) > 0 {
|
||||
ann := discover.AnnounceV2{
|
||||
Magic: discover.AnnouncementMagicV2,
|
||||
ann := discover.Announce{
|
||||
Magic: discover.AnnouncementMagic,
|
||||
This: discover.Node{
|
||||
ID: pkt.NodeID,
|
||||
},
|
||||
|
@ -134,8 +134,8 @@ func (d *Discoverer) announcementPkt() []byte {
|
||||
addrs = append(addrs, Address{IP: bs, Port: uint16(addr.Port)})
|
||||
}
|
||||
}
|
||||
var pkt = AnnounceV2{
|
||||
Magic: AnnouncementMagicV2,
|
||||
var pkt = Announce{
|
||||
Magic: AnnouncementMagic,
|
||||
This: Node{d.myID[:], addrs},
|
||||
}
|
||||
return pkt.MarshalXDR()
|
||||
@ -144,8 +144,8 @@ func (d *Discoverer) announcementPkt() []byte {
|
||||
func (d *Discoverer) sendLocalAnnouncements() {
|
||||
var addrs = resolveAddrs(d.listenAddrs)
|
||||
|
||||
var pkt = AnnounceV2{
|
||||
Magic: AnnouncementMagicV2,
|
||||
var pkt = Announce{
|
||||
Magic: AnnouncementMagic,
|
||||
This: Node{d.myID[:], addrs},
|
||||
}
|
||||
|
||||
@ -191,8 +191,8 @@ func (d *Discoverer) sendExternalAnnouncements() {
|
||||
|
||||
var buf []byte
|
||||
if d.extPort != 0 {
|
||||
var pkt = AnnounceV2{
|
||||
Magic: AnnouncementMagicV2,
|
||||
var pkt = Announce{
|
||||
Magic: AnnouncementMagic,
|
||||
This: Node{d.myID[:], []Address{{Port: d.extPort}}},
|
||||
}
|
||||
buf = pkt.MarshalXDR()
|
||||
@ -244,7 +244,7 @@ func (d *Discoverer) recvAnnouncements() {
|
||||
l.Debugf("discover: read announcement:\n%s", hex.Dump(buf))
|
||||
}
|
||||
|
||||
var pkt AnnounceV2
|
||||
var pkt Announce
|
||||
err := pkt.UnmarshalXDR(buf)
|
||||
if err != nil && err != io.EOF {
|
||||
continue
|
||||
@ -331,7 +331,7 @@ func (d *Discoverer) externalLookup(node protocol.NodeID) []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
buf := QueryV2{QueryMagicV2, node[:]}.MarshalXDR()
|
||||
buf := Query{QueryMagic, node[:]}.MarshalXDR()
|
||||
_, err = conn.Write(buf)
|
||||
if err != nil {
|
||||
if debug {
|
||||
@ -357,7 +357,7 @@ func (d *Discoverer) externalLookup(node protocol.NodeID) []string {
|
||||
l.Debugf("discover: read external:\n%s", hex.Dump(buf[:n]))
|
||||
}
|
||||
|
||||
var pkt AnnounceV2
|
||||
var pkt Announce
|
||||
err = pkt.UnmarshalXDR(buf[:n])
|
||||
if err != nil && err != io.EOF {
|
||||
if debug {
|
||||
|
@ -5,16 +5,16 @@
|
||||
package discover
|
||||
|
||||
const (
|
||||
AnnouncementMagicV2 = 0x029E4C77
|
||||
QueryMagicV2 = 0x23D63A9A
|
||||
AnnouncementMagic = 0x9D79BC39
|
||||
QueryMagic = 0x2CA856F5
|
||||
)
|
||||
|
||||
type QueryV2 struct {
|
||||
type Query struct {
|
||||
Magic uint32
|
||||
NodeID []byte // max:32
|
||||
}
|
||||
|
||||
type AnnounceV2 struct {
|
||||
type Announce struct {
|
||||
Magic uint32
|
||||
This Node
|
||||
Extra []Node // max:16
|
||||
|
@ -17,7 +17,7 @@ import (
|
||||
|
||||
/*
|
||||
|
||||
QueryV2 Structure:
|
||||
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
|
||||
@ -32,30 +32,30 @@ QueryV2 Structure:
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
|
||||
|
||||
struct QueryV2 {
|
||||
struct Query {
|
||||
unsigned int Magic;
|
||||
opaque NodeID<32>;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
func (o QueryV2) EncodeXDR(w io.Writer) (int, error) {
|
||||
func (o Query) EncodeXDR(w io.Writer) (int, error) {
|
||||
var xw = xdr.NewWriter(w)
|
||||
return o.encodeXDR(xw)
|
||||
}
|
||||
|
||||
func (o QueryV2) MarshalXDR() []byte {
|
||||
func (o Query) MarshalXDR() []byte {
|
||||
return o.AppendXDR(make([]byte, 0, 128))
|
||||
}
|
||||
|
||||
func (o QueryV2) AppendXDR(bs []byte) []byte {
|
||||
func (o Query) AppendXDR(bs []byte) []byte {
|
||||
var aw = xdr.AppendWriter(bs)
|
||||
var xw = xdr.NewWriter(&aw)
|
||||
o.encodeXDR(xw)
|
||||
return []byte(aw)
|
||||
}
|
||||
|
||||
func (o QueryV2) encodeXDR(xw *xdr.Writer) (int, error) {
|
||||
func (o Query) encodeXDR(xw *xdr.Writer) (int, error) {
|
||||
xw.WriteUint32(o.Magic)
|
||||
if len(o.NodeID) > 32 {
|
||||
return xw.Tot(), xdr.ErrElementSizeExceeded
|
||||
@ -64,18 +64,18 @@ func (o QueryV2) encodeXDR(xw *xdr.Writer) (int, error) {
|
||||
return xw.Tot(), xw.Error()
|
||||
}
|
||||
|
||||
func (o *QueryV2) DecodeXDR(r io.Reader) error {
|
||||
func (o *Query) DecodeXDR(r io.Reader) error {
|
||||
xr := xdr.NewReader(r)
|
||||
return o.decodeXDR(xr)
|
||||
}
|
||||
|
||||
func (o *QueryV2) UnmarshalXDR(bs []byte) error {
|
||||
func (o *Query) UnmarshalXDR(bs []byte) error {
|
||||
var br = bytes.NewReader(bs)
|
||||
var xr = xdr.NewReader(br)
|
||||
return o.decodeXDR(xr)
|
||||
}
|
||||
|
||||
func (o *QueryV2) decodeXDR(xr *xdr.Reader) error {
|
||||
func (o *Query) decodeXDR(xr *xdr.Reader) error {
|
||||
o.Magic = xr.ReadUint32()
|
||||
o.NodeID = xr.ReadBytesMax(32)
|
||||
return xr.Error()
|
||||
@ -83,7 +83,7 @@ func (o *QueryV2) decodeXDR(xr *xdr.Reader) error {
|
||||
|
||||
/*
|
||||
|
||||
AnnounceV2 Structure:
|
||||
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
|
||||
@ -100,7 +100,7 @@ AnnounceV2 Structure:
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
|
||||
|
||||
struct AnnounceV2 {
|
||||
struct Announce {
|
||||
unsigned int Magic;
|
||||
Node This;
|
||||
Node Extra<16>;
|
||||
@ -108,23 +108,23 @@ struct AnnounceV2 {
|
||||
|
||||
*/
|
||||
|
||||
func (o AnnounceV2) EncodeXDR(w io.Writer) (int, error) {
|
||||
func (o Announce) EncodeXDR(w io.Writer) (int, error) {
|
||||
var xw = xdr.NewWriter(w)
|
||||
return o.encodeXDR(xw)
|
||||
}
|
||||
|
||||
func (o AnnounceV2) MarshalXDR() []byte {
|
||||
func (o Announce) MarshalXDR() []byte {
|
||||
return o.AppendXDR(make([]byte, 0, 128))
|
||||
}
|
||||
|
||||
func (o AnnounceV2) AppendXDR(bs []byte) []byte {
|
||||
func (o Announce) AppendXDR(bs []byte) []byte {
|
||||
var aw = xdr.AppendWriter(bs)
|
||||
var xw = xdr.NewWriter(&aw)
|
||||
o.encodeXDR(xw)
|
||||
return []byte(aw)
|
||||
}
|
||||
|
||||
func (o AnnounceV2) encodeXDR(xw *xdr.Writer) (int, error) {
|
||||
func (o Announce) encodeXDR(xw *xdr.Writer) (int, error) {
|
||||
xw.WriteUint32(o.Magic)
|
||||
o.This.encodeXDR(xw)
|
||||
if len(o.Extra) > 16 {
|
||||
@ -137,18 +137,18 @@ func (o AnnounceV2) encodeXDR(xw *xdr.Writer) (int, error) {
|
||||
return xw.Tot(), xw.Error()
|
||||
}
|
||||
|
||||
func (o *AnnounceV2) DecodeXDR(r io.Reader) error {
|
||||
func (o *Announce) DecodeXDR(r io.Reader) error {
|
||||
xr := xdr.NewReader(r)
|
||||
return o.decodeXDR(xr)
|
||||
}
|
||||
|
||||
func (o *AnnounceV2) UnmarshalXDR(bs []byte) error {
|
||||
func (o *Announce) UnmarshalXDR(bs []byte) error {
|
||||
var br = bytes.NewReader(bs)
|
||||
var xr = xdr.NewReader(br)
|
||||
return o.decodeXDR(xr)
|
||||
}
|
||||
|
||||
func (o *AnnounceV2) decodeXDR(xr *xdr.Reader) error {
|
||||
func (o *Announce) decodeXDR(xr *xdr.Reader) error {
|
||||
o.Magic = xr.ReadUint32()
|
||||
(&o.This).decodeXDR(xr)
|
||||
_ExtraSize := int(xr.ReadUint32())
|
||||
|
Loading…
Reference in New Issue
Block a user