close the server when leaving
This commit is contained in:
parent
ca35fd19db
commit
73068a9c1f
@ -11,8 +11,9 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
|
|
||||||
"git.sunturtle.xyz/zephyr/chord/chord"
|
|
||||||
"github.com/go-json-experiment/json"
|
"github.com/go-json-experiment/json"
|
||||||
|
|
||||||
|
"git.sunturtle.xyz/zephyr/chord/chord"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Node struct {
|
type Node struct {
|
||||||
@ -22,6 +23,9 @@ type Node struct {
|
|||||||
// TODO(branden): really we should have a client per peer so that we can
|
// TODO(branden): really we should have a client per peer so that we can
|
||||||
// interchange protocols
|
// interchange protocols
|
||||||
client chord.Client
|
client chord.Client
|
||||||
|
// l is the listener that the HTTP server serves.
|
||||||
|
// When the server leaves, it closes the listener.
|
||||||
|
l net.Listener
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates an instance of a Chord network that responds on HTTP.
|
// New creates an instance of a Chord network that responds on HTTP.
|
||||||
@ -39,6 +43,7 @@ func New(l net.Listener, cl chord.Client, self *chord.Node) (*Node, error) {
|
|||||||
r := &Node{
|
r := &Node{
|
||||||
self: self,
|
self: self,
|
||||||
client: cl,
|
client: cl,
|
||||||
|
l: l,
|
||||||
}
|
}
|
||||||
return r, nil
|
return r, nil
|
||||||
}
|
}
|
||||||
@ -165,4 +170,6 @@ func (n *Node) bye(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
n.self.Leave(p, s)
|
n.self.Leave(p, s)
|
||||||
w.WriteHeader(http.StatusNoContent)
|
w.WriteHeader(http.StatusNoContent)
|
||||||
|
// Close the listener so that the server will shut down.
|
||||||
|
n.l.Close()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user