diff --git a/node/bindata.go b/node/bindata.go index 8ec2a79e677aaae9f4a63fb6383b652488626f80..ac86f0623967bb58b1c988af2742561904c21b12 100644 --- a/node/bindata.go +++ b/node/bindata.go @@ -272,21 +272,21 @@ var _templatesIndexHtml = []byte(`<!DOCTYPE html> {{$domain := .Domain}} {{range .Mounts}} <li> - <a href="http://{{$domain}}{{.Mount.Name}}" + <a href="http://{{$domain}}{{.Mount.Path}}" {{if .Mount.RelayUrl}} data-toggle="tooltip" data-delay="300" title="relay of {{.Mount.RelayUrl}}" {{end}} - >{{.Mount.Name}}</a> - <a href="http://{{$domain}}{{.Mount.Name}}.m3u">(m3u)</a> + >{{.Mount.Path}}</a> + <a href="http://{{$domain}}{{.Mount.Path}}.m3u">(m3u)</a> <span class="badge">{{.Listeners}}</span> {{if .TransMounts}} <ul> {{range .TransMounts}} <li> - <a href="http://{{$domain}}{{.Mount.Name}}" + <a href="http://{{$domain}}{{.Mount.Path}}" data-toggle="tooltip" data-delay="300" title="{{.Mount.Transcoding.String}}" - >{{.Mount.Name}}</a> - <a href="http://{{$domain}}{{.Mount.Name}}.m3u">(m3u)</a> + >{{.Mount.Path}}</a> + <a href="http://{{$domain}}{{.Mount.Path}}.m3u">(m3u)</a> <span class="badge">{{.Listeners}}</span> </li> {{end}} @@ -339,7 +339,7 @@ func templatesIndexHtml() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "templates/index.html", size: 2567, mode: os.FileMode(420), modTime: time.Unix(1543702463, 0)} + info := bindataFileInfo{name: "templates/index.html", size: 2567, mode: os.FileMode(420), modTime: time.Unix(1555111991, 0)} a := &asset{bytes: bytes, info: info} return a, nil } diff --git a/node/node_test.go b/node/node_test.go index 653a230b255102180ce2a04ff252d2252d97affd..a218b7515aa52c176e0c449be359fbe3c69df3e0 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -5,11 +5,15 @@ import ( "fmt" "log" "net" + "net/http" + "net/http/httptest" "os" "testing" "time" + "git.autistici.org/ale/autoradio" pb "git.autistici.org/ale/autoradio/proto" + "github.com/golang/protobuf/proto" "go.etcd.io/etcd/clientv3/concurrency" "go.etcd.io/etcd/embed" "go.etcd.io/etcd/etcdserver/api/v3client" @@ -33,6 +37,7 @@ func TestNode(t *testing.T) { if err != nil { t.Fatalf("StartEtcd: %v", err) } + defer e.Close() <-e.Server.ReadyNotify() cli := v3client.New(e.Server) @@ -70,3 +75,59 @@ func TestNode(t *testing.T) { n.Wait() } } + +func TestNode_StatusPage(t *testing.T) { + cfg := embed.NewConfig() + cfg.Dir = "default.etcd" + defer os.RemoveAll(cfg.Dir) + e, err := embed.StartEtcd(cfg) + if err != nil { + t.Fatalf("StartEtcd: %v", err) + } + defer e.Close() + <-e.Server.ReadyNotify() + + cli := v3client.New(e.Server) + + session, _ := concurrency.NewSession(cli, concurrency.WithTTL(2)) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + // Create a new Mount + m := &pb.Mount{ + Path: "/test.ogg", + SourceUsername: "user", + SourcePassword: "pass", + } + mdata, _ := proto.Marshal(m) + _, err = cli.Put(ctx, autoradio.MountPrefix+"test.ogg", string(mdata)) + if err != nil { + t.Fatalf("Put error: %v", err) + } + + n, err := New( + ctx, + session, + &fakeIcecast{}, + "node1", + []net.IP{net.ParseIP("127.0.0.1")}, + net.ParseIP("127.0.0.1"), + 4014, + "random", + 0, 0, + ) + if err != nil { + t.Fatalf("NewNode: %v", err) + } + + httpSrv := httptest.NewServer(newHTTPHandler(n, 8080, "example.com")) + + resp, err := http.Get(httpSrv.URL) + if err != nil { + t.Fatalf("http.Get error: %v", err) + } + defer resp.Body.Close() + if resp.StatusCode != 200 { + t.Fatalf("HTTP response: %s", resp.Status) + } +} diff --git a/node/server.go b/node/server.go index a9d53b449420d95b1c1c1e1adbb1b7172847baef..b9fc6a432a4571d886ea8bedc8e41488a4054582 100644 --- a/node/server.go +++ b/node/server.go @@ -78,17 +78,22 @@ func (s *Server) Wait() error { // NewServer creates a new Server. Will use publicAddrs / peerAddr to // build all the necessary addr/port combinations. +// +// The main http handler will bind on all available interfaces. The +// DNS servers will bind only to the publicAddrs (both TCP and +// UDP). The metrics and the status services, which are internal, will +// bind on peerAddr. func NewServer(n *Node, domain string, nameservers []string, publicAddrs []net.IP, peerAddr net.IP, httpPort, dnsPort, gossipPort, icecastPort, metricsPort int) *Server { httpHandler := newHTTPHandler(n, icecastPort, domain) dnsHandler := newDNSHandler(n, domain, nameservers) servers := []genericServer{ newStatusServer(mkaddr(peerAddr, gossipPort), n.statusMgr), + newHTTPServer("main", fmt.Sprintf(":%d", httpPort), httpHandler), newHTTPServer("metrics", fmt.Sprintf(":%d", metricsPort), newMetricsHandler()), } for _, ip := range publicAddrs { servers = append(servers, - newHTTPServer("main", mkaddr(ip, httpPort), httpHandler), newDNSServer("dns(udp)", mkaddr(ip, dnsPort), "udp", dnsHandler), newDNSServer("dns(tcp)", mkaddr(ip, dnsPort), "tcp", dnsHandler), ) diff --git a/node/templates/index.html b/node/templates/index.html index 1b95732d4a98425de82a412b0b13ae6ec2112155..cfcd9052304a2803b2fe1b7af3e02fea8d171e67 100644 --- a/node/templates/index.html +++ b/node/templates/index.html @@ -25,21 +25,21 @@ {{$domain := .Domain}} {{range .Mounts}} <li> - <a href="http://{{$domain}}{{.Mount.Name}}" + <a href="http://{{$domain}}{{.Mount.Path}}" {{if .Mount.RelayUrl}} data-toggle="tooltip" data-delay="300" title="relay of {{.Mount.RelayUrl}}" {{end}} - >{{.Mount.Name}}</a> - <a href="http://{{$domain}}{{.Mount.Name}}.m3u">(m3u)</a> + >{{.Mount.Path}}</a> + <a href="http://{{$domain}}{{.Mount.Path}}.m3u">(m3u)</a> <span class="badge">{{.Listeners}}</span> {{if .TransMounts}} <ul> {{range .TransMounts}} <li> - <a href="http://{{$domain}}{{.Mount.Name}}" + <a href="http://{{$domain}}{{.Mount.Path}}" data-toggle="tooltip" data-delay="300" title="{{.Mount.Transcoding.String}}" - >{{.Mount.Name}}</a> - <a href="http://{{$domain}}{{.Mount.Name}}.m3u">(m3u)</a> + >{{.Mount.Path}}</a> + <a href="http://{{$domain}}{{.Mount.Path}}.m3u">(m3u)</a> <span class="badge">{{.Listeners}}</span> </li> {{end}}