Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4c5d644
Parent tweaks
neilalexander Aug 20, 2021
167597c
Remove separate root record
neilalexander Aug 20, 2021
d5083e7
Fix bugs in spanning tree
neilalexander Aug 20, 2021
b4ae9d9
Other bug fixes
neilalexander Aug 20, 2021
d620f99
Merge branch 'main' into neilalexander/parent
neilalexander Aug 20, 2021
919be97
Tweaks
neilalexander Aug 23, 2021
b8a32ee
Some light refactoring to see if we can improve de-parenting performa…
neilalexander Aug 23, 2021
199423c
Detect ancestor parent changes, tweaks
neilalexander Sep 1, 2021
3e28429
Various refactoring, fixes and tweaks that might hopefully make paren…
neilalexander Sep 2, 2021
fd385ef
Simplify parent selection again (extra iterations are ultimately unne…
neilalexander Sep 3, 2021
58332b4
Reuse port numbers if possible, bug fixes
neilalexander Sep 3, 2021
ae12ac4
Well this isn't an improvement at all
neilalexander Sep 6, 2021
30d8b9f
Refactor announcements a bit
neilalexander Sep 7, 2021
3c89e4a
Refactor peer management
neilalexander Sep 7, 2021
d1d2d8c
Refactor root sequence
neilalexander Sep 7, 2021
fa612d8
Various tweaks
neilalexander Sep 8, 2021
eb08e94
Well that was incredibly tedious
neilalexander Sep 9, 2021
498bcb5
Tuning
neilalexander Sep 10, 2021
9a5de50
Check direct peers in default case
neilalexander Sep 10, 2021
cad3a62
Bootstrap faster if we lose the port that our ascending node was reac…
neilalexander Sep 10, 2021
02ac105
De-race SNEK a bit
neilalexander Sep 10, 2021
5b02c13
The moment a peer is cancelled, it should be marked as no longer started
neilalexander Sep 10, 2021
e0b542f
This is backward-incompatible
neilalexander Sep 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions cmd/pinecone/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,9 @@ func main() {
}

dialer := net.Dialer{
Timeout: time.Second * 5,
KeepAlive: time.Second * 2,
}
listener := net.ListenConfig{
KeepAlive: time.Second * 2,
Timeout: time.Second * 5,
}
listener := net.ListenConfig{}

pineconeRouter := router.NewRouter(logger, "router", sk, pk, nil)
_ = sessions.NewSessions(logger, pineconeRouter)
Expand Down
46 changes: 35 additions & 11 deletions cmd/pineconeip/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import (
"log"
"net"
"os"
"os/signal"
"runtime/pprof"
"syscall"
"time"

"net/http"
_ "net/http/pprof"
Expand Down Expand Up @@ -52,9 +56,15 @@ func main() {

logger := log.New(os.Stdout, "", 0)
if hostPort := os.Getenv("PPROFLISTEN"); hostPort != "" {
logger.Println("Starting pprof on", hostPort)
go func() {
_ = http.ListenAndServe(hostPort, nil)
listener, err := net.Listen("tcp", hostPort)
if err != nil {
panic(err)
}
logger.Println("Starting pprof on", listener.Addr())
if err := http.Serve(listener, nil); err != nil {
panic(err)
}
}()
}

Expand All @@ -72,14 +82,6 @@ func main() {
if err := conn.SetNoDelay(true); err != nil {
return fmt.Errorf("conn.SetNoDelay: %w", err)
}
/*
if err := conn.SetKeepAlive(true); err != nil {
return fmt.Errorf("conn.SetKeepAlive: %w", err)
}
if err := conn.SetKeepAlivePeriod(time.Second); err != nil {
return fmt.Errorf("conn.SetKeepAlivePeriod: %w", err)
}
*/
if err := conn.SetLinger(0); err != nil {
return fmt.Errorf("conn.SetLinger: %w", err)
}
Expand Down Expand Up @@ -133,5 +135,27 @@ func main() {
}
}()

select {}
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGUSR1)
for {
switch <-sigs {
case syscall.SIGUSR1:
fn := fmt.Sprintf("/tmp/profile.%d", os.Getpid())
logger.Println("Requested profile:", fn)
fp, err := os.Create(fn)
if err != nil {
logger.Println("Failed to create profile:", err)
return
}
defer fp.Close()
if err := pprof.StartCPUProfile(fp); err != nil {
logger.Println("Failed to start profiling:", err)
return
}
time.AfterFunc(time.Second*10, func() {
pprof.StopCPUProfile()
logger.Println("Profile written:", fn)
})
}
}
}
4 changes: 2 additions & 2 deletions cmd/pineconesim/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ <h4>Node Summary</h4>
</tr>
{{range .Nodes}}
{{if not .IsExternal}}<tr>
<td>{{.Name}}</td>
<td><a href="?view=snek&pk={{.Key}}">{{.Name}}</a></td>
<td><code>{{.Port}}</code></td>
<td><code>{{.Coords}}</code></td>
<td><a href="?view=snek&pk={{.Root}}"><code>{{.Root}}</code></a></td>
Expand Down Expand Up @@ -208,7 +208,7 @@ <h4>Peers</h4>
</tr>
{{range .NodeInfo.Peers}}
<tr>
<td><code>{{.Name}}</code></td>
<td><code><a href="?view=snek&pk={{.PublicKey}}">{{.Name}}</a></code></td>
<td><code><a href="?view=snek&pk={{.PublicKey}}">{{.PublicKey}}</a></code></td>
<td><code>{{.Port}}</code></td>
<td><code><a href="?view=snek&pk={{.RootPublicKey}}">{{.RootPublicKey}}</a></code></td>
Expand Down
6 changes: 6 additions & 0 deletions cmd/pineconesim/simulator/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
)

func (sim *Simulator) LookupCoords(target string) (types.SwitchPorts, error) {
sim.nodesMutex.RLock()
defer sim.nodesMutex.RUnlock()
node, ok := sim.nodes[target]
if !ok {
return nil, fmt.Errorf("node %q not known", target)
Expand All @@ -31,6 +33,8 @@ func (sim *Simulator) LookupCoords(target string) (types.SwitchPorts, error) {
}

func (sim *Simulator) LookupNodeID(target types.SwitchPorts) (string, error) {
sim.nodesMutex.RLock()
defer sim.nodesMutex.RUnlock()
for id, n := range sim.nodes {
if n.Coords().EqualTo(target) {
return id, nil
Expand All @@ -40,6 +44,8 @@ func (sim *Simulator) LookupNodeID(target types.SwitchPorts) (string, error) {
}

func (sim *Simulator) LookupPublicKey(target types.PublicKey) (string, error) {
sim.nodesMutex.RLock()
defer sim.nodesMutex.RUnlock()
for id, n := range sim.nodes {
if n.PublicKey().EqualTo(target) {
return id, nil
Expand Down
3 changes: 3 additions & 0 deletions cmd/pineconesim/simulator/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ func (sim *Simulator) CreateNode(t string) error {
if err := c.SetNoDelay(true); err != nil {
panic(err)
}
if err := c.SetLinger(0); err != nil {
panic(err)
}
if _, err = n.AuthenticatedConnect(c, "sim", router.PeerTypeRemote); err != nil {
continue
}
Expand Down
9 changes: 5 additions & 4 deletions multicast/multicast.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,14 @@ func NewMulticast(
}
m.tcpLC = net.ListenConfig{
Control: m.tcpOptions,
KeepAlive: time.Second,
KeepAlive: time.Second * 3,
}
m.udpLC = net.ListenConfig{
Control: m.udpOptions,
}
m.dialer = net.Dialer{
Control: m.tcpOptions,
Timeout: time.Second * 5,
KeepAlive: time.Second,
Control: m.tcpOptions,
// Timeout: time.Second * 5,
}
return m
}
Expand Down Expand Up @@ -163,6 +162,7 @@ func (m *Multicast) accept(listener net.Listener) {

if _, err := m.r.AuthenticatedConnect(conn, tcpaddr.Zone, router.PeerTypeMulticast); err != nil {
//m.log.Println("m.s.AuthenticatedConnect:", err)
_ = conn.Close()
continue
}
}
Expand Down Expand Up @@ -309,6 +309,7 @@ func (m *Multicast) listen(intf *multicastInterface, conn net.PacketConn, srcadd

if _, err := m.r.AuthenticatedConnect(peer, udpaddr.Zone, router.PeerTypeMulticast); err != nil {
m.log.Println("m.s.AuthenticatedConnect:", err)
_ = peer.Close()
continue
}
}
Expand Down
1 change: 1 addition & 0 deletions multicast/platform_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build darwin
// +build darwin

package multicast
Expand Down
4 changes: 2 additions & 2 deletions router/dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
type dhtEntry interface {
PublicKey() types.PublicKey
Coordinates() types.SwitchPorts
SeenRecently() bool
Alive() bool
}

type dht struct {
Expand Down Expand Up @@ -59,7 +59,7 @@ func (d *dht) table() []dhtEntry {

results := make([]dhtEntry, 0, len(d.sorted))
for _, n := range d.sorted {
if n.SeenRecently() {
if n.Alive() {
results = append(results, n)
}
}
Expand Down
4 changes: 3 additions & 1 deletion router/nexthop.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ func (p *Peer) getNextHops(frame *types.Frame, from types.SwitchPortID) types.Sw
switch frame.Type {
case types.TypeSTP:
if from != 0 {
p.r.handleAnnouncement(p, frame)
if err := p.r.handleAnnouncement(p, frame); err != nil {
p.r.log.Println("Failed to handle announcement:", err)
}
}

case types.TypeVirtualSnakeBootstrap:
Expand Down
8 changes: 5 additions & 3 deletions router/nexthop_greedy.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ func (r *Router) getGreedyRoutedNextHop(from *Peer, rx *types.Frame) types.Switc
peerCoords := p.Coordinates()
peerDist := int64(peerCoords.DistanceTo(rx.Destination))
switch {
case peerDist == 0:
return []types.SwitchPortID{p.port}
case rx.Destination.EqualTo(peerCoords):
case peerDist == 0 || rx.Destination.EqualTo(peerCoords):
// The peer is the actual destination.
return []types.SwitchPortID{p.port}

case peerDist < bestDist:
// The peer is closer to the destination.
bestPeer, bestDist = p.port, peerDist

default:
}
}
Expand Down
2 changes: 1 addition & 1 deletion router/nexthop_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (r *Router) getSourceRoutedNextHop(from *Peer, rx *types.Frame) types.Switc
return nil
}

if peer := r.ports[to]; !peer.started.Load() || !peer.alive.Load() {
if peer := r.ports[to]; !peer.started.Load() || !peer.Alive() {
// Don't try to send packets to a port that has nothing
// connected to it or isn't alive.
return nil
Expand Down
Loading