Reformatted with 'go fmt'
This commit is contained in:
1 parent
de7f4df7c9
commit
16e9daf057
5 files changed
+24
-25
No files matched your search
+3
-3
@@ -99,7 +99,7 @@ func (conn *LocalConnection) CheckFatal(err error) error {
|
|||||||
func (conn *LocalConnection) setEffectivePMTU(pmtu int) {
|
func (conn *LocalConnection) setEffectivePMTU(pmtu int) {
|
||||||
conn.Lock()
|
conn.Lock()
|
||||||
defer conn.Unlock()
|
defer conn.Unlock()
|
||||||
if (conn.effectivePMTU != pmtu) {
|
if conn.effectivePMTU != pmtu {
|
||||||
conn.effectivePMTU = pmtu
|
conn.effectivePMTU = pmtu
|
||||||
conn.log("Effective PMTU set to", pmtu)
|
conn.log("Effective PMTU set to", pmtu)
|
||||||
}
|
}
|
||||||
@@ -345,8 +345,8 @@ func (conn *LocalConnection) handshake(acceptNewPeer bool) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !acceptNewPeer {
|
if !acceptNewPeer {
|
||||||
if _, found := conn.Router.Peers.Fetch(name); !found {
|
if _, found := conn.Router.Peers.Fetch(name); !found {
|
||||||
return fmt.Errorf("Found unknown remote name: %s at %s", name, conn.remoteTCPAddr)
|
return fmt.Errorf("Found unknown remote name: %s at %s", name, conn.remoteTCPAddr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+9
-9
@@ -23,16 +23,16 @@ const (
|
|||||||
func StartConnectionMaker(router *Router) *ConnectionMaker {
|
func StartConnectionMaker(router *Router) *ConnectionMaker {
|
||||||
queryChan := make(chan *ConnectionMakerInteraction, ChannelSize)
|
queryChan := make(chan *ConnectionMakerInteraction, ChannelSize)
|
||||||
state := &ConnectionMaker{
|
state := &ConnectionMaker{
|
||||||
router: router,
|
router: router,
|
||||||
queryChan: queryChan,
|
queryChan: queryChan,
|
||||||
targets: make(map[string]*Target)}
|
targets: make(map[string]*Target)}
|
||||||
go state.queryLoop(queryChan)
|
go state.queryLoop(queryChan)
|
||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cm *ConnectionMaker) InitiateConnection(address string) {
|
func (cm *ConnectionMaker) InitiateConnection(address string) {
|
||||||
cm.queryChan <- &ConnectionMakerInteraction{
|
cm.queryChan <- &ConnectionMakerInteraction{
|
||||||
Interaction: Interaction{code: CMEnsure},
|
Interaction: Interaction{code: CMEnsure},
|
||||||
acceptAnyPeer: true,
|
acceptAnyPeer: true,
|
||||||
address: address}
|
address: address}
|
||||||
}
|
}
|
||||||
@@ -43,9 +43,9 @@ func (cm *ConnectionMaker) EnsureConnection(address string) {
|
|||||||
address = addrHost
|
address = addrHost
|
||||||
}
|
}
|
||||||
cm.queryChan <- &ConnectionMakerInteraction{
|
cm.queryChan <- &ConnectionMakerInteraction{
|
||||||
Interaction: Interaction{code: CMEnsure},
|
Interaction: Interaction{code: CMEnsure},
|
||||||
acceptAnyPeer: false,
|
acceptAnyPeer: false,
|
||||||
address: address}
|
address: address}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cm *ConnectionMaker) ConnectionEstablished(address string) {
|
func (cm *ConnectionMaker) ConnectionEstablished(address string) {
|
||||||
@@ -115,7 +115,7 @@ func (cm *ConnectionMaker) queryLoop(queryChan <-chan *ConnectionMakerInteractio
|
|||||||
for address, target := range cm.targets {
|
for address, target := range cm.targets {
|
||||||
if !target.established && !target.attempting && now.After(target.tryAfter) {
|
if !target.established && !target.attempting && now.After(target.tryAfter) {
|
||||||
target.attemptCount += 1
|
target.attemptCount += 1
|
||||||
target.attempting = true;
|
target.attempting = true
|
||||||
go cm.attemptConnection(address, target.acceptAnyPeer)
|
go cm.attemptConnection(address, target.acceptAnyPeer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -140,13 +140,13 @@ func (cm *ConnectionMaker) resetTarget(address string) {
|
|||||||
target.established = false
|
target.established = false
|
||||||
after, interval := tryImmediately()
|
after, interval := tryImmediately()
|
||||||
target.tryInterval = interval
|
target.tryInterval = interval
|
||||||
target.tryAfter = after
|
target.tryAfter = after
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cm *ConnectionMaker) status() string {
|
func (cm *ConnectionMaker) status() string {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
for address, target := range cm.targets {
|
for address, target := range cm.targets {
|
||||||
if (target.established) {
|
if target.established {
|
||||||
buf.WriteString(fmt.Sprintf("%s connected\n", address))
|
buf.WriteString(fmt.Sprintf("%s connected\n", address))
|
||||||
} else if target.attempting {
|
} else if target.attempting {
|
||||||
buf.WriteString(fmt.Sprintf("%s (%v attempts, trying since %v)\n", address, target.attemptCount, target.tryAfter))
|
buf.WriteString(fmt.Sprintf("%s (%v attempts, trying since %v)\n", address, target.attemptCount, target.tryAfter))
|
||||||
|
|||||||
+1
-1
@@ -11,7 +11,7 @@ import (
|
|||||||
type PeerCache struct {
|
type PeerCache struct {
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
table map[PeerName]*Peer
|
table map[PeerName]*Peer
|
||||||
onGC func(*Peer)
|
onGC func(*Peer)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPeerCache(onGC func(*Peer)) *PeerCache {
|
func NewPeerCache(onGC func(*Peer)) *PeerCache {
|
||||||
|
|||||||
@@ -160,19 +160,19 @@ type ConnectionMakerInteraction struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ConnectionMaker struct {
|
type ConnectionMaker struct {
|
||||||
router *Router
|
router *Router
|
||||||
queryChan chan<- *ConnectionMakerInteraction
|
queryChan chan<- *ConnectionMakerInteraction
|
||||||
targets map[string]*Target
|
targets map[string]*Target
|
||||||
}
|
}
|
||||||
|
|
||||||
// Information about an address where we may find a peer
|
// Information about an address where we may find a peer
|
||||||
type Target struct {
|
type Target struct {
|
||||||
acceptAnyPeer bool // was this address given to us on the command line?
|
acceptAnyPeer bool // was this address given to us on the command line?
|
||||||
attempting bool // are we currently attempting to connect to this address?
|
attempting bool // are we currently attempting to connect to this address?
|
||||||
established bool // has the connection been established
|
established bool // has the connection been established
|
||||||
tryAfter time.Time // next time to try this address
|
tryAfter time.Time // next time to try this address
|
||||||
tryInterval time.Duration // backoff time on next failure
|
tryInterval time.Duration // backoff time on next failure
|
||||||
attemptCount int
|
attemptCount int
|
||||||
}
|
}
|
||||||
|
|
||||||
// UDPSender interface and implementations
|
// UDPSender interface and implementations
|
||||||
|
|||||||
+2
-3
@@ -1,13 +1,13 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/zettio/weave"
|
|
||||||
"code.google.com/p/gopacket/layers"
|
"code.google.com/p/gopacket/layers"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"github.com/davecheney/profile"
|
"github.com/davecheney/profile"
|
||||||
|
"github.com/zettio/weave"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -141,7 +141,6 @@ func handleHttp(router *weave.Router) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func handleSignals(router *weave.Router) {
|
func handleSignals(router *weave.Router) {
|
||||||
sigs := make(chan os.Signal, 1)
|
sigs := make(chan os.Signal, 1)
|
||||||
signal.Notify(sigs, syscall.SIGQUIT, syscall.SIGUSR1)
|
signal.Notify(sigs, syscall.SIGQUIT, syscall.SIGUSR1)
|
||||||
|
|||||||
Reference in new issue
Block a user