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