diff --git a/Makefile.am b/Makefile.am index 658575d3..25a5e306 100644 --- a/Makefile.am +++ b/Makefile.am @@ -27,15 +27,13 @@ CONFIG_FILE ?= spreed-webrtc-server.conf CONFIG_PATH ?= /etc GOBUILDFLAGS ?= GOTESTFLAGS ?= -DESTDIR ?= / + +BIN ?= @prefix@/sbin +SHARE ?= @prefix@/share/spreed-webrtc-server OUTPUT := $(CURDIR)/bin OUTPUT_JS := $(CURDIR)/build/out -BIN := $(DESTDIR)@prefix@/sbin -CONFIG_DIR := $(DESTDIR)@prefix@$(CONFIG_PATH) -SHARE := $(DESTDIR)@prefix@/share/spreed-webrtc-server - BUILD_ARCH := $(shell $(GO) env GOARCH) BUILD_OS := $(shell go env GOOS) DIST := $(CURDIR)/dist_$(BUILD_ARCH) @@ -119,9 +117,9 @@ release: OUTPUT = $(DIST_BIN) release: $(DIST_BIN) binary releaseassets install: - echo $(BIN) - echo $(SHARE) - $(INSTALL) -d $(BIN) $(CONFIG_DIR) + @echo "Installing binaries to: $(BIN)" + @echo "Installing static resources to: $(SHARE)" + $(INSTALL) -d $(BIN) $(INSTALL) -d $(SHARE)/www/html $(INSTALL) -d $(SHARE)/www/static $(INSTALL) -d $(SHARE)/www/static/img @@ -131,7 +129,6 @@ install: $(INSTALL) -d $(SHARE)/www/static/css $(INSTALL) -d $(SHARE)/www/static/js/libs/pdf $(INSTALL) bin/$(EXENAME) $(BIN) - $(INSTALL) -m 644 server.conf.in $(CONFIG_DIR)/$(CONFIG_FILE) $(INSTALL) html/* $(SHARE)/www/html $(INSTALL) static/img/* $(SHARE)/www/static/img $(INSTALL) static/sounds/* $(SHARE)/www/static/sounds @@ -166,11 +163,11 @@ $(DIST_BIN): tarball: TARPATH = $(DIST)/$(PACKAGE_NAME)-$(PACKAGE_VERSION) tarball: BIN = $(TARPATH)/loader -tarball: CONFIG_DIR = $(TARPATH)/loader -tarball: DOCS = $(CONFIG_DIR)/docs +tarball: DOCS = $(TARPATH)/loader/docs tarball: SHARE = $(TARPATH)/ tarball: distclean release install echo -n $(PACKAGE_VERSION) > $(TARPATH)/version.txt + cp server.conf.in $(TARPATH)/loader tar czf $(DIST)/$(PACKAGE_NAME)-$(PACKAGE_VERSION)_$(BUILD_OS)_$(BUILD_ARCH).tar.gz -C $(DIST) $(PACKAGE_NAME)-$(PACKAGE_VERSION) .PHONY: clean distclean vendorclean pristine get getupdate build javascript fonts styles release releasetest dist_gopath install gopath binary binaryrace binaryall tarball assets diff --git a/debian/changelog b/debian/changelog index 528811c2..222a7823 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +spreed-webrtc-server (0.23.5) precise; urgency=low + + * No longer install config file in install target of Makefile. We leave it to the packaging. + * Sessions are no longer cleaned up when another connection replaced the session and a stale connection gets disconnected after that. + + -- Simon Eisenmann Wed, 11 Feb 2015 11:16:47 +0100 + spreed-webrtc-server (0.23.4) precise; urgency=low * Cleanup of README. diff --git a/src/app/spreed-webrtc-server/channelling_api.go b/src/app/spreed-webrtc-server/channelling_api.go index 96ea1db8..e3cbce04 100644 --- a/src/app/spreed-webrtc-server/channelling_api.go +++ b/src/app/spreed-webrtc-server/channelling_api.go @@ -32,6 +32,7 @@ const ( type ChannellingAPI interface { OnConnect(Client, *Session) + OnDisconnect(Client, *Session) OnIncoming(ResponseSender, *Session, *DataIncoming) } @@ -64,6 +65,10 @@ func (api *channellingAPI) OnConnect(client Client, session *Session) { api.SendSelf(client, session) } +func (api *channellingAPI) OnDisconnect(client Client, session *Session) { + api.Unicaster.OnDisconnect(client, session) +} + func (api *channellingAPI) OnIncoming(c ResponseSender, session *Session, msg *DataIncoming) { switch msg.Type { case "Self": diff --git a/src/app/spreed-webrtc-server/client.go b/src/app/spreed-webrtc-server/client.go index 1a437605..8900df7b 100644 --- a/src/app/spreed-webrtc-server/client.go +++ b/src/app/spreed-webrtc-server/client.go @@ -43,6 +43,7 @@ type Client interface { Session() *Session Index() uint64 Close() + ReplaceAndClose() } type client struct { @@ -61,6 +62,11 @@ func (client *client) OnConnect(conn Connection) { client.ChannellingAPI.OnConnect(client, client.session) } +func (client *client) OnDisconnect() { + client.session.Close() + client.ChannellingAPI.OnDisconnect(client, client.session) +} + func (client *client) OnText(b Buffer) { if incoming, err := client.DecodeIncoming(b); err == nil { client.OnIncoming(client, client.session, incoming) @@ -81,3 +87,10 @@ func (client *client) Reply(iid string, m interface{}) { func (client *client) Session() *Session { return client.session } + +func (client *client) ReplaceAndClose() { + client.session.Close() + if client.Connection != nil { + client.Connection.Close() + } +} diff --git a/src/app/spreed-webrtc-server/connection.go b/src/app/spreed-webrtc-server/connection.go index f99e405e..6ba7b456 100644 --- a/src/app/spreed-webrtc-server/connection.go +++ b/src/app/spreed-webrtc-server/connection.go @@ -64,6 +64,7 @@ type Connection interface { type ConnectionHandler interface { NewBuffer() Buffer OnConnect(Connection) + OnDisconnect() OnText(Buffer) } @@ -167,6 +168,7 @@ func (c *connection) readPump() { } c.Close() + c.handler.OnDisconnect() } // Write message to outbound queue. diff --git a/src/app/spreed-webrtc-server/hub.go b/src/app/spreed-webrtc-server/hub.go index 9a899f12..a5aefc12 100644 --- a/src/app/spreed-webrtc-server/hub.go +++ b/src/app/spreed-webrtc-server/hub.go @@ -48,8 +48,8 @@ type SessionStore interface { type Unicaster interface { SessionStore OnConnect(Client, *Session) + OnDisconnect(Client, *Session) Unicast(to string, outgoing *DataOutgoing) - OnDisconnect(sessionID string) } type ContactManager interface { @@ -150,26 +150,27 @@ func (h *hub) GetSession(id string) (session *Session, ok bool) { } func (h *hub) OnConnect(client Client, session *Session) { - // Set flags. - h.mutex.Lock() - - log.Printf("Created client with id %s", session.Id) - + log.Printf("Created client %d with id %s\n", client.Index(), session.Id) // Register connection or replace existing one. if ec, ok := h.clients[session.Id]; ok { - ec.Close() - //log.Printf("Register (%d) from %s: %s (existing)\n", c.Idx, c.Id) + log.Printf("Closing obsolete client %d with id %s\n", ec.Index(), session.Id) + ec.ReplaceAndClose() } h.clients[session.Id] = client - //fmt.Println("registered", c.Id) h.mutex.Unlock() - //log.Printf("Register (%d) from %s: %s\n", c.Idx, c.Id) } -func (h *hub) OnDisconnect(sessionID string) { +func (h *hub) OnDisconnect(client Client, session *Session) { h.mutex.Lock() - delete(h.clients, sessionID) + if ec, ok := h.clients[session.Id]; ok { + if ec == client { + log.Printf("Cleaning up client %d for session id %s\n", ec.Index(), session.Id) + delete(h.clients, session.Id) + } else { + log.Printf("Not cleaning up session %s as client %d was replaced with %d\n", session.Id, client.Index(), ec.Index()) + } + } h.mutex.Unlock() } diff --git a/src/app/spreed-webrtc-server/session.go b/src/app/spreed-webrtc-server/session.go index 2a040511..2adcc0e2 100644 --- a/src/app/spreed-webrtc-server/session.go +++ b/src/app/spreed-webrtc-server/session.go @@ -204,6 +204,10 @@ func (s *Session) Unicast(to string, m interface{}) { func (s *Session) Close() { s.mutex.Lock() + if s.disconnected { + s.mutex.Unlock() + return + } outgoing := &DataOutgoing{ From: s.Id, @@ -230,7 +234,6 @@ func (s *Session) Close() { session.RemoveSubscriber(s.Id) } - s.Unicaster.OnDisconnect(s.Id) s.SessionManager.DestroySession(s.Id, s.userid) s.buddyImages.Delete(s.Id) diff --git a/src/app/spreed-webrtc-server/ws.go b/src/app/spreed-webrtc-server/ws.go index 3cd7fb1e..70ad83fd 100644 --- a/src/app/spreed-webrtc-server/ws.go +++ b/src/app/spreed-webrtc-server/ws.go @@ -69,7 +69,6 @@ func makeWSHandler(connectionCounter ConnectionCounter, sessionManager SessionMa // Create a new connection instance. session := sessionManager.CreateSession(r) - defer session.Close() client := NewClient(codec, channellingAPI, session) conn := NewConnection(connectionCounter.CountConnection(), ws, client)