-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
703 additions
and
617 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
# legacy ndt-server code | ||
|
||
All code in this directory tree is related to the support of the legacy NDT | ||
protocol. We have many extant clients that use this protocol, and we don't want | ||
to leave them high and dry, but new clients are encouraged to use the services | ||
provided by the ndt7 subtree. The test is streamlined, the client is easier to | ||
protocol. We have many extant clients that use this protocol, and we don't | ||
want to leave them high and dry, but new clients are encouraged to use the | ||
services provided by ndt7. The test is streamlined, the client is easier to | ||
write, and basically everything about it is better. | ||
|
||
In this tree, we support existing clients, but we will be adding no new | ||
functionality. | ||
In this subtree, we support existing clients, but we will be adding no new | ||
functionality. If you are reading this and trying to decide how to implement | ||
a speed test, use ndt7 and not the legacy protocol. The legacy protocol is | ||
deprecated. It will be supported until usage drops to very low levels, but it | ||
is also not recommended for new integrations or code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package handler | ||
|
||
import ( | ||
"log" | ||
"net/http" | ||
|
||
"github.com/m-lab/go/warnonerror" | ||
"github.com/m-lab/ndt-server/legacy" | ||
"github.com/m-lab/ndt-server/legacy/protocol" | ||
"github.com/m-lab/ndt-server/legacy/singleserving" | ||
"github.com/m-lab/ndt-server/legacy/ws" | ||
) | ||
|
||
type httpFactory struct{} | ||
|
||
func (hf *httpFactory) SingleServingServer(dir string) (singleserving.Server, error) { | ||
return singleserving.StartWS(dir) | ||
} | ||
|
||
// httpHandler handles requests that come in over HTTP or HTTPS. It should be | ||
// created with MakeHTTPHandler() or MakeHTTPSHandler(). | ||
type httpHandler struct { | ||
serverFactory singleserving.Factory | ||
} | ||
|
||
// ServeHTTP is the command channel for the NDT-WS or NDT-WSS test. All | ||
// subsequent client communication is synchronized with this method. Returning | ||
// closes the websocket connection, so only occurs after all tests complete or | ||
// an unrecoverable error. It is called ServeHTTP to make sure that the Server | ||
// implements the http.Handler interface. | ||
func (s *httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | ||
upgrader := ws.Upgrader("ndt") | ||
wsc, err := upgrader.Upgrade(w, r, nil) | ||
if err != nil { | ||
log.Println("ERROR SERVER:", err) | ||
return | ||
} | ||
ws := protocol.AdaptWsConn(wsc) | ||
defer warnonerror.Close(ws, "Could not close connection") | ||
legacy.HandleControlChannel(ws, s.serverFactory) | ||
} | ||
|
||
// NewWS returns a handler suitable for http-based connections. | ||
func NewWS() http.Handler { | ||
return &httpHandler{ | ||
serverFactory: &httpFactory{}, | ||
} | ||
} | ||
|
||
type httpsFactory struct { | ||
certFile string | ||
keyFile string | ||
} | ||
|
||
func (hf *httpsFactory) SingleServingServer(dir string) (singleserving.Server, error) { | ||
return singleserving.StartWSS(dir, hf.certFile, hf.keyFile) | ||
} | ||
|
||
// NewWSS returns a handler suitable for https-based connections. | ||
func NewWSS(certFile, keyFile string) http.Handler { | ||
return &httpHandler{ | ||
serverFactory: &httpsFactory{ | ||
certFile: certFile, | ||
keyFile: keyFile, | ||
}, | ||
} | ||
} |
Oops, something went wrong.