mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-09 23:00:58 +00:00
beacon.Beacon -> beacon.Broadcast
This commit is contained in:
parent
52219c5f3f
commit
a1fd07b27c
@ -16,7 +16,7 @@ type dst struct {
|
|||||||
conn *net.UDPConn
|
conn *net.UDPConn
|
||||||
}
|
}
|
||||||
|
|
||||||
type Beacon struct {
|
type Broadcast struct {
|
||||||
conn *net.UDPConn
|
conn *net.UDPConn
|
||||||
port int
|
port int
|
||||||
conns []dst
|
conns []dst
|
||||||
@ -24,12 +24,12 @@ type Beacon struct {
|
|||||||
outbox chan recv
|
outbox chan recv
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(port int) (*Beacon, error) {
|
func NewBroadcast(port int) (*Broadcast, error) {
|
||||||
conn, err := net.ListenUDP("udp", &net.UDPAddr{Port: port})
|
conn, err := net.ListenUDP("udp", &net.UDPAddr{Port: port})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
b := &Beacon{
|
b := &Broadcast{
|
||||||
conn: conn,
|
conn: conn,
|
||||||
port: port,
|
port: port,
|
||||||
inbox: make(chan []byte),
|
inbox: make(chan []byte),
|
||||||
@ -42,21 +42,21 @@ func New(port int) (*Beacon, error) {
|
|||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Beacon) Send(data []byte) {
|
func (b *Broadcast) Send(data []byte) {
|
||||||
b.inbox <- data
|
b.inbox <- data
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Beacon) Recv() ([]byte, net.Addr) {
|
func (b *Broadcast) Recv() ([]byte, net.Addr) {
|
||||||
recv := <-b.outbox
|
recv := <-b.outbox
|
||||||
return recv.data, recv.src
|
return recv.data, recv.src
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Beacon) reader() {
|
func (b *Broadcast) reader() {
|
||||||
bs := make([]byte, 65536)
|
bs := make([]byte, 65536)
|
||||||
for {
|
for {
|
||||||
n, addr, err := b.conn.ReadFrom(bs)
|
n, addr, err := b.conn.ReadFrom(bs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Warnln("Beacon read:", err)
|
l.Warnln("Broadcast read:", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if debug {
|
if debug {
|
||||||
@ -75,12 +75,12 @@ func (b *Beacon) reader() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Beacon) writer() {
|
func (b *Broadcast) writer() {
|
||||||
for bs := range b.inbox {
|
for bs := range b.inbox {
|
||||||
|
|
||||||
addrs, err := net.InterfaceAddrs()
|
addrs, err := net.InterfaceAddrs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Warnln("Beacon: interface addresses:", err)
|
l.Warnln("Broadcast: interface addresses:", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
@ -26,7 +26,7 @@ type Discoverer struct {
|
|||||||
globalBcastIntv time.Duration
|
globalBcastIntv time.Duration
|
||||||
errorRetryIntv time.Duration
|
errorRetryIntv time.Duration
|
||||||
cacheLifetime time.Duration
|
cacheLifetime time.Duration
|
||||||
beacon *beacon.Beacon
|
broadcastBeacon *beacon.Broadcast
|
||||||
registry map[protocol.NodeID][]cacheEntry
|
registry map[protocol.NodeID][]cacheEntry
|
||||||
registryLock sync.RWMutex
|
registryLock sync.RWMutex
|
||||||
extServer string
|
extServer string
|
||||||
@ -55,7 +55,7 @@ var (
|
|||||||
const maxErrors = 30
|
const maxErrors = 30
|
||||||
|
|
||||||
func NewDiscoverer(id protocol.NodeID, addresses []string, localPort int) (*Discoverer, error) {
|
func NewDiscoverer(id protocol.NodeID, addresses []string, localPort int) (*Discoverer, error) {
|
||||||
b, err := beacon.New(localPort)
|
b, err := beacon.NewBroadcast(localPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -66,7 +66,7 @@ func NewDiscoverer(id protocol.NodeID, addresses []string, localPort int) (*Disc
|
|||||||
globalBcastIntv: 1800 * time.Second,
|
globalBcastIntv: 1800 * time.Second,
|
||||||
errorRetryIntv: 60 * time.Second,
|
errorRetryIntv: 60 * time.Second,
|
||||||
cacheLifetime: 5 * time.Minute,
|
cacheLifetime: 5 * time.Minute,
|
||||||
beacon: b,
|
broadcastBeacon: b,
|
||||||
registry: make(map[protocol.NodeID][]cacheEntry),
|
registry: make(map[protocol.NodeID][]cacheEntry),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,7 +187,7 @@ func (d *Discoverer) sendLocalAnnouncements() {
|
|||||||
msg := pkt.MarshalXDR()
|
msg := pkt.MarshalXDR()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
d.beacon.Send(msg)
|
d.broadcastBeacon.Send(msg)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-d.localBcastTick:
|
case <-d.localBcastTick:
|
||||||
@ -286,7 +286,7 @@ loop:
|
|||||||
|
|
||||||
func (d *Discoverer) recvAnnouncements() {
|
func (d *Discoverer) recvAnnouncements() {
|
||||||
for {
|
for {
|
||||||
buf, addr := d.beacon.Recv()
|
buf, addr := d.broadcastBeacon.Recv()
|
||||||
|
|
||||||
if debug {
|
if debug {
|
||||||
l.Debugf("discover: read announcement from %s:\n%s", addr, hex.Dump(buf))
|
l.Debugf("discover: read announcement from %s:\n%s", addr, hex.Dump(buf))
|
||||||
|
Loading…
Reference in New Issue
Block a user