Merge branch '1.0'

This commit is contained in:
Matthias Radestock committed 2015-07-13 19:07:47 +01:00
commit 85b4a05c9a
3 files changed
+85 -7

No files matched your search

+9 -6
View File
@@ -14,16 +14,17 @@ import (
)
const (
macMaxAge = 10 * time.Minute // [1]
tcpAcceptDelay = 1 * time.Millisecond // [2]
macMaxAge = 10 * time.Minute // [1]
acceptMaxTokens = 100 // [2]
acceptTokenDelay = 100 * time.Millisecond // [3]
)
// [1] should be greater than typical ARP cache expiries, i.e. > 3/2 *
// /proc/sys/net/ipv4_neigh/*/base_reachable_time_ms on Linux
// [2] time to wait between accepting tcp connections. This guards
// against brute-force attacks on the password when encryption is in
// use. It is also a basic DoS defence.
// [2] capacity of token bucket for rate limiting accepts
// [3] control rate at which new tokens are added to the bucket
type LogFrameFunc func(string, []byte, *EthernetDecoder)
@@ -48,6 +49,7 @@ type Router struct {
gossipChannels GossipChannels
TopologyGossip Gossip
UDPListener *net.UDPConn
acceptLimiter *TokenBucket
}
type PacketSource interface {
@@ -80,6 +82,7 @@ func NewRouter(config Config, name PeerName, nickName string) *Router {
router.Routes = NewRoutes(router.Ourself, router.Peers)
router.ConnectionMaker = NewConnectionMaker(router.Ourself, router.Peers, router.Port, router.PeerDiscovery)
router.TopologyGossip = router.NewGossip("topology", router)
router.acceptLimiter = NewTokenBucket(acceptMaxTokens, acceptTokenDelay)
return router
}
@@ -206,7 +209,7 @@ func (router *Router) listenTCP(localPort int) {
continue
}
router.acceptTCP(tcpConn)
time.Sleep(tcpAcceptDelay)
router.acceptLimiter.Wait()
}
}()
}