From 7cdbb786d6f8ecf2c4c2f17ecf6d38d8a89780b1 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Wed, 31 Oct 2018 20:42:21 -0700 Subject: [PATCH] watchtower/wtserver: move from watchtower/server --- watchtower/{server => wtserver}/interface.go | 2 +- watchtower/{server => wtserver}/log.go | 2 +- watchtower/{server => wtserver}/mock.go | 2 +- watchtower/{server => wtserver}/server.go | 2 +- .../{server => wtserver}/server_test.go | 38 +++++++++---------- 5 files changed, 23 insertions(+), 23 deletions(-) rename watchtower/{server => wtserver}/interface.go (99%) rename watchtower/{server => wtserver}/log.go (97%) rename watchtower/{server => wtserver}/mock.go (99%) rename watchtower/{server => wtserver}/server.go (99%) rename watchtower/{server => wtserver}/server_test.go (94%) diff --git a/watchtower/server/interface.go b/watchtower/wtserver/interface.go similarity index 99% rename from watchtower/server/interface.go rename to watchtower/wtserver/interface.go index 98a99213..69d4ec9c 100644 --- a/watchtower/server/interface.go +++ b/watchtower/wtserver/interface.go @@ -1,4 +1,4 @@ -package server +package wtserver import ( "io" diff --git a/watchtower/server/log.go b/watchtower/wtserver/log.go similarity index 97% rename from watchtower/server/log.go rename to watchtower/wtserver/log.go index 38dc44f2..7939bd97 100644 --- a/watchtower/server/log.go +++ b/watchtower/wtserver/log.go @@ -1,4 +1,4 @@ -package server +package wtserver import ( "github.com/btcsuite/btclog" diff --git a/watchtower/server/mock.go b/watchtower/wtserver/mock.go similarity index 99% rename from watchtower/server/mock.go rename to watchtower/wtserver/mock.go index 54e0bf96..758e4ae2 100644 --- a/watchtower/server/mock.go +++ b/watchtower/wtserver/mock.go @@ -1,6 +1,6 @@ // +build dev -package server +package wtserver import ( "fmt" diff --git a/watchtower/server/server.go b/watchtower/wtserver/server.go similarity index 99% rename from watchtower/server/server.go rename to watchtower/wtserver/server.go index 6bc8ac0d..99230276 100644 --- a/watchtower/server/server.go +++ b/watchtower/wtserver/server.go @@ -1,4 +1,4 @@ -package server +package wtserver import ( "bytes" diff --git a/watchtower/server/server_test.go b/watchtower/wtserver/server_test.go similarity index 94% rename from watchtower/server/server_test.go rename to watchtower/wtserver/server_test.go index f36e2698..3ca056af 100644 --- a/watchtower/server/server_test.go +++ b/watchtower/wtserver/server_test.go @@ -1,6 +1,6 @@ // +build dev -package server_test +package wtserver_test import ( "bytes" @@ -12,8 +12,8 @@ import ( "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcutil" "github.com/lightningnetwork/lnd/lnwire" - "github.com/lightningnetwork/lnd/watchtower/server" "github.com/lightningnetwork/lnd/watchtower/wtdb" + "github.com/lightningnetwork/lnd/watchtower/wtserver" "github.com/lightningnetwork/lnd/watchtower/wtwire" ) @@ -36,8 +36,8 @@ func randPubKey(t *testing.T) *btcec.PublicKey { // initServer creates and starts a new server using the server.DB and timeout. // If the provided database is nil, a mock db will be used. -func initServer(t *testing.T, db server.DB, - timeout time.Duration) server.Interface { +func initServer(t *testing.T, db wtserver.DB, + timeout time.Duration) wtserver.Interface { t.Helper() @@ -45,7 +45,7 @@ func initServer(t *testing.T, db server.DB, db = wtdb.NewMockDB() } - s, err := server.New(&server.Config{ + s, err := wtserver.New(&wtserver.Config{ DB: db, ReadTimeout: timeout, WriteTimeout: timeout, @@ -79,8 +79,8 @@ func TestServerOnlyAcceptOnePeer(t *testing.T) { // Create two peers using the same session id. peerPub := randPubKey(t) - peer1 := server.NewMockPeer(peerPub, nil, 0) - peer2 := server.NewMockPeer(peerPub, nil, 0) + peer1 := wtserver.NewMockPeer(peerPub, nil, 0) + peer2 := wtserver.NewMockPeer(peerPub, nil, 0) // Serialize a Init message to be sent by both peers. init := wtwire.NewInitMessage( @@ -106,8 +106,8 @@ func TestServerOnlyAcceptOnePeer(t *testing.T) { // Try to send a message on either peer, and record the opposite peer as // the one we assume to be rejected. var ( - rejectedPeer *server.MockPeer - acceptedPeer *server.MockPeer + rejectedPeer *wtserver.MockPeer + acceptedPeer *wtserver.MockPeer ) select { case peer1.IncomingMsgs <- msg: @@ -192,7 +192,7 @@ func testServerCreateSession(t *testing.T, i int, test createSessionTestCase) { // Create a new client and connect to server. peerPub := randPubKey(t) - peer := server.NewMockPeer(peerPub, nil, 0) + peer := wtserver.NewMockPeer(peerPub, nil, 0) connect(t, i, s, peer, test.initMsg, timeoutDuration) // Send the CreateSession message, and wait for a reply. @@ -220,7 +220,7 @@ func testServerCreateSession(t *testing.T, i int, test createSessionTestCase) { // Simulate a peer with the same session id connection to the server // again. - peer = server.NewMockPeer(peerPub, nil, 0) + peer = wtserver.NewMockPeer(peerPub, nil, 0) connect(t, i, s, peer, test.initMsg, timeoutDuration) // Send the _same_ CreateSession message as the first attempt. @@ -492,7 +492,7 @@ func testServerStateUpdates(t *testing.T, i int, test stateUpdateTestCase) { // Create a new client and connect to the server. peerPub := randPubKey(t) - peer := server.NewMockPeer(peerPub, nil, 0) + peer := wtserver.NewMockPeer(peerPub, nil, 0) connect(t, i, s, peer, test.initMsg, timeoutDuration) // Register a session for this client to use in the subsequent tests. @@ -512,7 +512,7 @@ func testServerStateUpdates(t *testing.T, i int, test stateUpdateTestCase) { // Now that the original connection has been closed, connect a new // client with the same session id. - peer = server.NewMockPeer(peerPub, nil, 0) + peer = wtserver.NewMockPeer(peerPub, nil, 0) connect(t, i, s, peer, test.initMsg, timeoutDuration) // Send the intended StateUpdate messages in series. @@ -523,7 +523,7 @@ func testServerStateUpdates(t *testing.T, i int, test stateUpdateTestCase) { if update == nil { assertConnClosed(t, peer, 2*timeoutDuration) - peer = server.NewMockPeer(peerPub, nil, 0) + peer = wtserver.NewMockPeer(peerPub, nil, 0) connect(t, i, s, peer, test.initMsg, timeoutDuration) continue @@ -547,7 +547,7 @@ func testServerStateUpdates(t *testing.T, i int, test stateUpdateTestCase) { assertConnClosed(t, peer, 2*timeoutDuration) } -func connect(t *testing.T, i int, s server.Interface, peer *server.MockPeer, +func connect(t *testing.T, i int, s wtserver.Interface, peer *wtserver.MockPeer, initMsg *wtwire.Init, timeout time.Duration) { s.InboundPeerConnected(peer) @@ -555,9 +555,9 @@ func connect(t *testing.T, i int, s server.Interface, peer *server.MockPeer, recvReply(t, i, "Init", peer, timeout) } -// sendMsg sends a wtwire.Message message via a server.MockPeer. +// sendMsg sends a wtwire.Message message via a wtserver.MockPeer. func sendMsg(t *testing.T, i int, msg wtwire.Message, - peer *server.MockPeer, timeout time.Duration) { + peer *wtserver.MockPeer, timeout time.Duration) { t.Helper() @@ -579,7 +579,7 @@ func sendMsg(t *testing.T, i int, msg wtwire.Message, // expected reply type. The supported replies are CreateSessionReply and // StateUpdateReply. func recvReply(t *testing.T, i int, name string, - peer *server.MockPeer, timeout time.Duration) wtwire.Message { + peer *wtserver.MockPeer, timeout time.Duration) wtwire.Message { t.Helper() @@ -623,7 +623,7 @@ func recvReply(t *testing.T, i int, name string, // assertConnClosed checks that the peer's connection is closed before the // timeout expires. -func assertConnClosed(t *testing.T, peer *server.MockPeer, duration time.Duration) { +func assertConnClosed(t *testing.T, peer *wtserver.MockPeer, duration time.Duration) { t.Helper() select {