Compare commits
25 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b2c6f313bc | |||
| b9f4c25f39 | |||
| 531abdafde | |||
| 9f0d81e7f1 | |||
| ed9d45d343 | |||
| a7b0a5d113 | |||
| 91be76b82e | |||
| 95c4a1738b | |||
| 607466dd65 | |||
| e3e80d450b | |||
| e995d436c2 | |||
| 0330d2d17f | |||
| 58a078b9f9 | |||
| 3baccaccac | |||
| 74123021be | |||
| 80d23b514c | |||
| 1026cc5dd9 | |||
| cb34fe2883 | |||
| b7558e9d01 | |||
| 767d8be277 | |||
| 239a6d6804 | |||
| 1491ad9351 | |||
| 96de06e4e0 | |||
| 8f9eb05ddb | |||
| c471f9f4cc |
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
.DS_Store
|
||||||
|
dist/
|
||||||
|
release/
|
||||||
50
.goreleaser.yaml
Normal file
50
.goreleaser.yaml
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
version: 2
|
||||||
|
|
||||||
|
before:
|
||||||
|
hooks:
|
||||||
|
- go mod tidy
|
||||||
|
- go test ./...
|
||||||
|
|
||||||
|
builds:
|
||||||
|
- env:
|
||||||
|
- CGO_ENABLED=0
|
||||||
|
goos:
|
||||||
|
- linux
|
||||||
|
- windows
|
||||||
|
- darwin
|
||||||
|
- freebsd
|
||||||
|
goarch:
|
||||||
|
- arm
|
||||||
|
- arm64
|
||||||
|
- amd64
|
||||||
|
goarm:
|
||||||
|
- 6
|
||||||
|
- 7
|
||||||
|
ignore:
|
||||||
|
- goos: darwin
|
||||||
|
goarch: arm
|
||||||
|
- goos: windows
|
||||||
|
goarch: arm
|
||||||
|
- goos: windows
|
||||||
|
goarch: arm64
|
||||||
|
- goos: freebsd
|
||||||
|
goarch: arm
|
||||||
|
|
||||||
|
|
||||||
|
archives:
|
||||||
|
- formats: [tar.gz]
|
||||||
|
# this name template makes the OS and Arch compatible with the results of `uname`.
|
||||||
|
name_template: >-
|
||||||
|
{{ .ProjectName }}_
|
||||||
|
{{- title .Os }}_
|
||||||
|
{{- if eq .Arch "amd64" }}x86_64
|
||||||
|
{{- else if eq .Arch "386" }}i386
|
||||||
|
{{- else }}{{ .Arch }}{{ end }}
|
||||||
|
{{- if .Arm }}v{{ .Arm }}{{ end }}
|
||||||
|
# use zip for windows archives
|
||||||
|
format_overrides:
|
||||||
|
- goos: windows
|
||||||
|
formats: [zip]
|
||||||
|
|
||||||
|
changelog:
|
||||||
|
disable: true
|
||||||
13
.vscode/settings.json
vendored
13
.vscode/settings.json
vendored
@@ -1,9 +1,20 @@
|
|||||||
{
|
{
|
||||||
"cSpell.words": [
|
"cSpell.words": [
|
||||||
|
"authtoken",
|
||||||
"Debugf",
|
"Debugf",
|
||||||
"Infof",
|
"Infof",
|
||||||
"isatty",
|
"isatty",
|
||||||
"netgiv",
|
"netgiv",
|
||||||
"pflag"
|
"ngfs",
|
||||||
|
"tardisx",
|
||||||
|
"ttys"
|
||||||
|
],
|
||||||
|
"cSpell.ignoreWords": [
|
||||||
|
"logrus",
|
||||||
|
"mattn",
|
||||||
|
"pflag",
|
||||||
|
"sigchan",
|
||||||
|
"sirupsen",
|
||||||
|
"verysecretvaluehere"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
21
LICENSE.txt
Normal file
21
LICENSE.txt
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2022 Justin Hawkins
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
141
README.md
141
README.md
@@ -1,3 +1,142 @@
|
|||||||
# netgiv
|
# netgiv
|
||||||
|
|
||||||
TBD
|
## What is this?
|
||||||
|
|
||||||
|
`netgiv` is a single binary client and server to facilitate sending files across
|
||||||
|
your local network quickly and easily.
|
||||||
|
|
||||||
|
It uses a familiar unix pipeline paradigm, so files can be moved between machines
|
||||||
|
as part of a pipeline, obviating the need for dealing with temporary files.
|
||||||
|
|
||||||
|
`netgiv` automatically detects "copy" (stdin is a pipe) or "paste" (stdout is a
|
||||||
|
pipe) modes, allowing intuitive use like:
|
||||||
|
|
||||||
|
hostA$ pg_dumpall | netgiv
|
||||||
|
|
||||||
|
hostB$ netgiv | psql restoredb
|
||||||
|
|
||||||
|
Note that since netgiv uses a persistent server, there is no need to setup both ends
|
||||||
|
of the pipeline in advance (compared to netcat or similar tools).
|
||||||
|
|
||||||
|
All data is encrypted in flight (though not in the temporary files on the server)
|
||||||
|
Access to the server is granted by an authentication token (preshared key) of your
|
||||||
|
choice.
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
### Binary release
|
||||||
|
|
||||||
|
Grab the appropriate version from https://github.com/tardisx/netgiv/releases, unzip
|
||||||
|
and place the binary somewhere on your $PATH.
|
||||||
|
|
||||||
|
Copy and paste for the trusting & lazy:
|
||||||
|
|
||||||
|
curl -L https://github.com/tardisx/netgiv/releases/download/v0.0.4/netgiv-linux-v0.0.4.zip | funzip > netgiv && chmod a+x netgiv
|
||||||
|
|
||||||
|
### Compiling from source
|
||||||
|
|
||||||
|
go install github.com/tardisx/netgiv@latest
|
||||||
|
|
||||||
|
`netgiv` should end up on your go binary path.
|
||||||
|
|
||||||
|
### Compiling from source
|
||||||
|
|
||||||
|
Clone this repository, run `go build`.
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
Configuration of `netgiv` is via a YAML configuration file in
|
||||||
|
`$HOME/.netgiv/config.yaml`.
|
||||||
|
|
||||||
|
Run `netgiv --help-config` to see a sample config file.
|
||||||
|
|
||||||
|
The server requires the 'authtoken' and 'port' configuration keys to be set.
|
||||||
|
|
||||||
|
The client requires the 'authtoken', 'port' and 'address' configuration keys to be
|
||||||
|
set.
|
||||||
|
|
||||||
|
* `authtoken` - this is any arbitrary string, you should choose something not easy to
|
||||||
|
guess
|
||||||
|
* `port` - this is the TCP port the server will listen on (and that the client will
|
||||||
|
connect to)
|
||||||
|
* `address` - the IP address or hostname of the `netgiv` server
|
||||||
|
|
||||||
|
## Running
|
||||||
|
|
||||||
|
To run a server, just run:
|
||||||
|
|
||||||
|
netgiv --server
|
||||||
|
|
||||||
|
`netgiv` will run in the foreground and log accesses to it.
|
||||||
|
|
||||||
|
On any client, run:
|
||||||
|
|
||||||
|
$ echo "Hello" | netgiv
|
||||||
|
|
||||||
|
To check for success, try:
|
||||||
|
|
||||||
|
$ netgiv | cat
|
||||||
|
|
||||||
|
You should see "hello" echoed on your terminal.
|
||||||
|
|
||||||
|
To check the list of files on the server:
|
||||||
|
|
||||||
|
$ netgiv -l
|
||||||
|
1: UTF-8 text (6 B)
|
||||||
|
2: application/x-mach-binary (6.5 MB)
|
||||||
|
3: video/quicktime (14 MB)
|
||||||
|
4: image/png (1.5 MB)
|
||||||
|
|
||||||
|
Note that netgiv tries to identify each file based on file magic heuristics.
|
||||||
|
|
||||||
|
If you would like to fetch (paste) a particular file:
|
||||||
|
|
||||||
|
netgiv -p 3 > file.mov
|
||||||
|
|
||||||
|
Where '3' comes from the information provided in the `-l` output.
|
||||||
|
|
||||||
|
Note that providing no `-p` option is the same as `-p X` where X is the highest
|
||||||
|
numbered upload (most recent).
|
||||||
|
|
||||||
|
### Notes on output
|
||||||
|
|
||||||
|
Since netgiv is designed to be used in a pipeline, it does not provide any
|
||||||
|
output on successful execution (apart from your actual data on stdout of course!)
|
||||||
|
|
||||||
|
If you'd like to see debugging information, use the `--debug` flag.
|
||||||
|
|
||||||
|
Note that `netgiv` will send error logs to stderr in cases of problems.
|
||||||
|
|
||||||
|
### Alternative ways of providing the authtoken
|
||||||
|
|
||||||
|
It's possible that you do not trust the hosts you are running the `netgiv` client on,
|
||||||
|
or otherwise not want to store your authtoken in a file on there. If that is the case
|
||||||
|
there are a couple of alternate options:
|
||||||
|
|
||||||
|
#### ENV var
|
||||||
|
|
||||||
|
The environment variable NETGIV_AUTHTOKEN can be used to provide the authtoken. A
|
||||||
|
common way to leverage this is to send it when you ssh to a remote host via the
|
||||||
|
`SendEnv` option (see your ssh_config man page).
|
||||||
|
|
||||||
|
#### Interactive
|
||||||
|
|
||||||
|
If the authtoken has not been set by any of the above methods, it will be prompted
|
||||||
|
for interactively (it will not be echoed to the screen). Note that this only applies
|
||||||
|
to the client - the server must have a config file with an authtoken specified.
|
||||||
|
|
||||||
|
# Other notes
|
||||||
|
|
||||||
|
## Temporary file storage
|
||||||
|
|
||||||
|
The `netgiv` server will store files in your normal system temporary dir. They will
|
||||||
|
be deleted when the server shuts down (SIGTERM). These files are *not* encrypted.
|
||||||
|
|
||||||
|
## Window support
|
||||||
|
|
||||||
|
Windows support is marginal, at best, mostly because of the lack of POSIX style
|
||||||
|
pipes. Bug reports and suggestions for workarounds are welcome.
|
||||||
|
|
||||||
|
# Acknowledgements
|
||||||
|
|
||||||
|
* thanks to tengig for the name
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
#!/usr/bin/env perl
|
|
||||||
|
|
||||||
use strict;
|
|
||||||
use warnings;
|
|
||||||
|
|
||||||
open my $fh, "<", "main.go" || die $!;
|
|
||||||
|
|
||||||
my $version;
|
|
||||||
while (<$fh>) {
|
|
||||||
# CurrentVersion: "v0.04"
|
|
||||||
$version = $1 if /CurrentVersion\s*=\s*"(v[\d\.]+)"/;
|
|
||||||
}
|
|
||||||
close $fh;
|
|
||||||
|
|
||||||
die "no version?" unless defined $version;
|
|
||||||
|
|
||||||
# quit if tests fail
|
|
||||||
system("go test ./...") && die "not building release with failing tests";
|
|
||||||
|
|
||||||
# so lazy
|
|
||||||
system "rm", "-rf", "release", "dist";
|
|
||||||
system "mkdir", "release";
|
|
||||||
system "mkdir", "dist";
|
|
||||||
|
|
||||||
my %build = (
|
|
||||||
win => { env => { GOOS => 'windows', GOARCH => 'amd64' }, filename => 'netgiv.exe' },
|
|
||||||
linux => { env => { GOOS => 'linux', GOARCH => 'amd64' }, filename => 'netgiv' },
|
|
||||||
mac => { env => { GOOS => 'darwin', GOARCH => 'amd64' }, filename => 'netgiv' },
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach my $type (keys %build) {
|
|
||||||
mkdir "release/$type";
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach my $type (keys %build) {
|
|
||||||
local $ENV{GOOS} = $build{$type}->{env}->{GOOS};
|
|
||||||
local $ENV{GOARCH} = $build{$type}->{env}->{GOARCH};
|
|
||||||
system "go", "build", "-o", "release/$type/" . $build{$type}->{filename};
|
|
||||||
system "zip", "-j", "dist/netgiv-$type-$version.zip", ( glob "release/$type/*" );
|
|
||||||
}
|
|
||||||
@@ -59,6 +59,7 @@ func (c *Client) Connect() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// now we expect to get stuff back until we don't
|
// now we expect to get stuff back until we don't
|
||||||
|
numFiles := 0
|
||||||
for {
|
for {
|
||||||
listPacket := secure.PacketListData{}
|
listPacket := secure.PacketListData{}
|
||||||
err := dec.Decode(&listPacket)
|
err := dec.Decode(&listPacket)
|
||||||
@@ -68,8 +69,10 @@ func (c *Client) Connect() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
fmt.Printf("%d: %s (%s)\n", listPacket.Id, listPacket.Kind, humanize.Bytes(uint64(listPacket.FileSize)))
|
fmt.Printf("%d: %s (%s) - %s\n", listPacket.Id, listPacket.Kind, humanize.Bytes(uint64(listPacket.FileSize)), listPacket.Timestamp)
|
||||||
|
numFiles++
|
||||||
}
|
}
|
||||||
|
fmt.Printf("total: %d files\n", numFiles)
|
||||||
conn.Close()
|
conn.Close()
|
||||||
log.Debugf("done listing")
|
log.Debugf("done listing")
|
||||||
|
|
||||||
@@ -180,7 +183,7 @@ func (c *Client) connectToServer(op secure.OperationTypeEnum, enc *gob.Encoder,
|
|||||||
startPacket := secure.PacketStartRequest{
|
startPacket := secure.PacketStartRequest{
|
||||||
OperationType: op,
|
OperationType: op,
|
||||||
ClientName: "",
|
ClientName: "",
|
||||||
ProtocolVersion: "1.0",
|
ProtocolVersion: ProtocolVersion,
|
||||||
AuthToken: c.authToken,
|
AuthToken: c.authToken,
|
||||||
}
|
}
|
||||||
err := enc.Encode(startPacket)
|
err := enc.Encode(startPacket)
|
||||||
|
|||||||
26
main.go
26
main.go
@@ -13,7 +13,7 @@ import (
|
|||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
var CurrentVersion = "v0.0.3"
|
const ProtocolVersion = "1.1"
|
||||||
|
|
||||||
type PasteValue struct {
|
type PasteValue struct {
|
||||||
PasteRequired bool
|
PasteRequired bool
|
||||||
@@ -69,6 +69,12 @@ func getAuthTokenFromTerminal() string {
|
|||||||
return pass
|
return pass
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
version = "dev"
|
||||||
|
commit = "none"
|
||||||
|
date = "unknown"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
isServer := flag.Bool("server", false, "Run netgiv in server mode")
|
isServer := flag.Bool("server", false, "Run netgiv in server mode")
|
||||||
|
|
||||||
@@ -89,8 +95,15 @@ func main() {
|
|||||||
flag.String("authtoken", "", "Authentication token")
|
flag.String("authtoken", "", "Authentication token")
|
||||||
flag.Int("port", 0, "Port")
|
flag.Int("port", 0, "Port")
|
||||||
|
|
||||||
|
versionFlag := flag.BoolP("version", "v", false, "show version and exit")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
if versionFlag != nil && *versionFlag {
|
||||||
|
fmt.Print(versionInfo(true))
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
receiveNum := int(pasteFlag.PasteNumber)
|
receiveNum := int(pasteFlag.PasteNumber)
|
||||||
if !pasteFlag.PasteRequired {
|
if !pasteFlag.PasteRequired {
|
||||||
receiveNum = -1
|
receiveNum = -1
|
||||||
@@ -110,7 +123,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
flag.Parse()
|
|
||||||
viper.BindPFlags(flag.CommandLine)
|
viper.BindPFlags(flag.CommandLine)
|
||||||
|
|
||||||
viper.SetEnvPrefix("NETGIV")
|
viper.SetEnvPrefix("NETGIV")
|
||||||
@@ -198,3 +210,13 @@ environment variable. This may be preferable in some environments.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func versionInfo(verbose bool) string {
|
||||||
|
out := ""
|
||||||
|
out += fmt.Sprintf("netgiv %s, built at %s\n", version, date)
|
||||||
|
if verbose {
|
||||||
|
out += fmt.Sprintf("commit: %s\n", commit)
|
||||||
|
out += fmt.Sprintf("http://github.com/tardisx/netgiv\n")
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
|
"time"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
@@ -226,8 +227,9 @@ type PacketReceiveDataNext struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PacketListData struct {
|
type PacketListData struct {
|
||||||
Id uint32
|
Id uint32
|
||||||
Filename string
|
Filename string
|
||||||
FileSize uint32
|
FileSize uint32
|
||||||
Kind string
|
Timestamp time.Time
|
||||||
|
Kind string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,22 +2,13 @@ package secure
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/gob"
|
||||||
"net"
|
"net"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPacketBasic(t *testing.T) {
|
func TestBasic(t *testing.T) {
|
||||||
// pSrc := PacketStart{
|
|
||||||
// OperationType: 0,
|
|
||||||
// ClientName: "test1",
|
|
||||||
// ProtocolVersion: "test2",
|
|
||||||
// AuthToken: "test3",
|
|
||||||
// }
|
|
||||||
// pDst := PacketStart{}
|
|
||||||
|
|
||||||
// buf := bytes.Buffer{}
|
|
||||||
|
|
||||||
srcConn, dstConn := net.Pipe()
|
srcConn, dstConn := net.Pipe()
|
||||||
|
|
||||||
srcSecConn := SecureConnection{
|
srcSecConn := SecureConnection{
|
||||||
@@ -71,6 +62,61 @@ func TestPacketBasic(t *testing.T) {
|
|||||||
t.Errorf("%v not equal to %v", out[:n], b)
|
t.Errorf("%v not equal to %v", out[:n], b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPacketBasic(t *testing.T) {
|
||||||
|
// test encoding/decoding of packets over the encrypted wire
|
||||||
|
srcConn, dstConn := net.Pipe()
|
||||||
|
|
||||||
|
srcSecConn := SecureConnection{
|
||||||
|
Conn: srcConn,
|
||||||
|
SharedKey: &[32]byte{0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
|
||||||
|
0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
|
||||||
|
0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
|
||||||
|
0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
|
||||||
|
},
|
||||||
|
Buffer: &bytes.Buffer{},
|
||||||
|
}
|
||||||
|
|
||||||
|
dstSecConn := SecureConnection{
|
||||||
|
Conn: dstConn,
|
||||||
|
SharedKey: &[32]byte{0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
|
||||||
|
0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
|
||||||
|
0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
|
||||||
|
0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
|
||||||
|
},
|
||||||
|
Buffer: &bytes.Buffer{},
|
||||||
|
}
|
||||||
|
|
||||||
|
enc := gob.NewEncoder(&srcSecConn)
|
||||||
|
dec := gob.NewDecoder(&dstSecConn)
|
||||||
|
|
||||||
|
packet := PacketStartRequest{
|
||||||
|
OperationType: OperationTypeReceive,
|
||||||
|
ClientName: "foo",
|
||||||
|
ProtocolVersion: "1.1",
|
||||||
|
AuthToken: "abc123",
|
||||||
|
}
|
||||||
|
go func() { enc.Encode(packet) }()
|
||||||
|
|
||||||
|
recvPacket := PacketStartRequest{}
|
||||||
|
dec.Decode(&recvPacket)
|
||||||
|
|
||||||
|
if recvPacket.OperationType != OperationTypeReceive {
|
||||||
|
t.Error("bad OperationType")
|
||||||
|
}
|
||||||
|
if recvPacket.ClientName != "foo" {
|
||||||
|
t.Error("bad ClientName")
|
||||||
|
}
|
||||||
|
if recvPacket.ClientName != "foo" {
|
||||||
|
t.Error("bad ClientName")
|
||||||
|
}
|
||||||
|
if recvPacket.AuthToken != "abc123" {
|
||||||
|
t.Error("bad AuthToken")
|
||||||
|
}
|
||||||
|
if recvPacket.ProtocolVersion != "1.1" {
|
||||||
|
t.Error("bad ProtocolVersion")
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
10
server.go
10
server.go
@@ -34,10 +34,15 @@ type NGF struct {
|
|||||||
Timestamp time.Time
|
Timestamp time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ngf NGF) String() string {
|
||||||
|
return fmt.Sprintf("id: %d, stored: %s, size: %d, kind: %s", ngf.Id, ngf.StorePath, ngf.Size, ngf.Kind)
|
||||||
|
}
|
||||||
|
|
||||||
var ngfs []NGF
|
var ngfs []NGF
|
||||||
var globalId uint32
|
var globalId uint32
|
||||||
|
|
||||||
func (s *Server) Run() {
|
func (s *Server) Run() {
|
||||||
|
log.Info(versionInfo(false))
|
||||||
log.Infof("starting server on :%d", s.port)
|
log.Infof("starting server on :%d", s.port)
|
||||||
address := fmt.Sprintf(":%d", s.port)
|
address := fmt.Sprintf(":%d", s.port)
|
||||||
networkAddress, _ := net.ResolveTCPAddr("tcp", address)
|
networkAddress, _ := net.ResolveTCPAddr("tcp", address)
|
||||||
@@ -105,10 +110,10 @@ func (s *Server) handleConnection(conn *net.TCPConn) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// tell teh client the dealio
|
// tell the client if the connection is ok.
|
||||||
startResponse := secure.PacketStartResponse{}
|
startResponse := secure.PacketStartResponse{}
|
||||||
|
|
||||||
if start.ProtocolVersion != "1.0" {
|
if start.ProtocolVersion != ProtocolVersion {
|
||||||
log.Errorf("bad protocol version")
|
log.Errorf("bad protocol version")
|
||||||
startResponse.Response = secure.PacketStartResponseEnumWrongProtocol
|
startResponse.Response = secure.PacketStartResponseEnumWrongProtocol
|
||||||
enc.Encode(startResponse)
|
enc.Encode(startResponse)
|
||||||
@@ -307,6 +312,7 @@ func (s *Server) handleConnection(conn *net.TCPConn) {
|
|||||||
p.Kind = ngf.Kind
|
p.Kind = ngf.Kind
|
||||||
p.Id = ngf.Id
|
p.Id = ngf.Id
|
||||||
p.Filename = ngf.Filename
|
p.Filename = ngf.Filename
|
||||||
|
p.Timestamp = ngf.Timestamp
|
||||||
enc.Encode(p)
|
enc.Encode(p)
|
||||||
}
|
}
|
||||||
log.Debugf("done sending list, closing connection")
|
log.Debugf("done sending list, closing connection")
|
||||||
|
|||||||
Reference in New Issue
Block a user