From 23600524a5bcdc3442340e4b465ac9a1f3ca2cca Mon Sep 17 00:00:00 2001 From: Martin Geno Date: Thu, 18 Jan 2018 15:25:52 +0100 Subject: [PATCH] allow ipv4 (for testing) --- database/yanic/main.go | 8 ++++++-- database/yanic/main_test.go | 26 +++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/database/yanic/main.go b/database/yanic/main.go index 61b867c..fbbb8f7 100644 --- a/database/yanic/main.go +++ b/database/yanic/main.go @@ -25,6 +25,10 @@ type Connection struct { type Config map[string]interface{} +func (c Config) Type() string { + return c["type"].(string) +} + func (c Config) Address() string { return c["address"].(string) } @@ -37,7 +41,7 @@ func Connect(configuration map[string]interface{}) (database.Connection, error) var config Config config = configuration - conn, err := net.Dial("udp6", config.Address()) + conn, err := net.Dial(config.Type(), config.Address()) if err != nil { return nil, err } @@ -54,7 +58,7 @@ func (conn *Connection) InsertNode(node *runtime.Node) { var b bytes.Buffer writer := bufio.NewWriter(&b) - flater, err := flate.NewWriter(writer, flate.NoCompression) + flater, err := flate.NewWriter(writer, flate.BestCompression) if err != nil { log.Printf("[database-yanic] could not create flater: %s", err) return diff --git a/database/yanic/main_test.go b/database/yanic/main_test.go index e6e21e2..c3ed048 100644 --- a/database/yanic/main_test.go +++ b/database/yanic/main_test.go @@ -3,6 +3,8 @@ package yanic import ( "testing" + "github.com/FreifunkBremen/yanic/data" + "github.com/FreifunkBremen/yanic/runtime" "github.com/stretchr/testify/assert" ) @@ -10,16 +12,38 @@ func TestStart(t *testing.T) { assert := assert.New(t) conn, err := Connect(map[string]interface{}{ + "type": "udp6", "address": "fasfs", }) assert.Nil(conn) assert.Error(err) conn, err = Connect(map[string]interface{}{ - "address": "[::1]:11001", + "type": "udp", + "address": "localhost:11001", }) assert.NoError(err) + conn.InsertNode(&runtime.Node{ + Nodeinfo: &data.NodeInfo{ + NodeID: "73deadbeaf13", + Hostname: "inject-test", + Network: data.Network{ + Mac: "73:de:ad:be:af:13", + Addresses: []string{"a", "b"}, + }, + }, + Statistics: &data.Statistics{ + NodeID: "73deadbeaf13", + Clients: data.Clients{ + Total: 1000, + Wifi: 500, + Wifi24: 100, + Wifi5: 300, + }, + }, + }) + conn.Close() }