Skip to content

Commit 9f0b3bf

Browse files
author
Alban Siffer
committed
update miner
1 parent be3eab6 commit 9f0b3bf

File tree

5 files changed

+13
-28
lines changed

5 files changed

+13
-28
lines changed

miner/config.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func SetPromiscuous(b bool) error {
8888
// SetSnapshotLen sets the maximum size of packets which are captured
8989
func SetSnapshotLen(sl int32) error {
9090
if sl <= 0 {
91-
return fmt.Errorf("Snapshot length must be strictly positive")
91+
return fmt.Errorf("snapshot length must be strictly positive")
9292
}
9393
snapshotLen = sl
9494
minerLogger.Debug().Msgf("Snapshot length set to %d", sl)
@@ -119,7 +119,7 @@ func SetDevice(dev string) error {
119119
device = dev
120120
iface = false
121121
} else {
122-
err := fmt.Errorf("Unknown device %s", dev)
122+
err := fmt.Errorf("unknown device %s", dev)
123123
minerLogger.Error().Msg(err.Error())
124124
return err
125125
}

miner/dispatcher.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func (d *Dispatcher) buildCounterList() {
136136
func (d *Dispatcher) load(name string) error {
137137
ctr, exists := counters.AvailableCounters[name]
138138
if !exists {
139-
return fmt.Errorf("The counter %s does not exists", name)
139+
return fmt.Errorf("the counter %s does not exists", name)
140140
}
141141
// ensure the counter is zero
142142
ctr.Reset()
@@ -148,7 +148,7 @@ func (d *Dispatcher) load(name string) error {
148148
func (d *Dispatcher) unload(name string) error {
149149
_, exists := counters.AvailableCounters[name]
150150
if !exists {
151-
return fmt.Errorf("The counter %s does not exists", name)
151+
return fmt.Errorf("the counter %s does not exists", name)
152152
}
153153

154154
delete(d.counters, name)

miner/miner.go

+4-20
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"os"
1212
"path"
1313
"strings"
14-
"sync"
1514
"time"
1615

1716
"github.com/asiffer/netspot/miner/counters"
@@ -42,7 +41,6 @@ var (
4241

4342
// Storing/Accessing the counters
4443
var (
45-
mux, valmux sync.RWMutex // Locker for the counter map access
4644
internalEventChannel = make(EventChannel, 1) // to receive events
4745
// externalDataChannel = make(DataChannel, 1) // to send data to the analyzer
4846
)
@@ -57,14 +55,6 @@ var (
5755
timeout time.Duration // time to wait if nothing happens
5856
)
5957

60-
// Packet sniffing/parsing
61-
var (
62-
handle *pcap.Handle
63-
// ringHandle *pfring.Ring
64-
parser *gopacket.DecodingLayerParser
65-
err error
66-
)
67-
6858
// Dispatcher
6959
var dispatcher = NewDispatcher()
7060

@@ -121,7 +111,7 @@ func InitLogger() {
121111
func Zero() error {
122112
if IsSniffing() {
123113
minerLogger.Error().Msg("Cannot reload, sniffing in progress")
124-
return errors.New("Cannot reload, sniffing in progress")
114+
return errors.New("cannot reload, sniffing in progress")
125115
}
126116

127117
reset()
@@ -323,11 +313,11 @@ func sniff(period time.Duration, data DataChannel) {
323313
// channel where counters are sent
324314
func Start(period time.Duration) (DataChannel, error) {
325315
if IsSniffing() {
326-
return nil, fmt.Errorf("Already sniffing")
316+
return nil, fmt.Errorf("already sniffing")
327317
}
328318
ctr := dispatcher.loadedCounters()
329319
if len(ctr) == 0 {
330-
return nil, fmt.Errorf("No counters loaded")
320+
return nil, fmt.Errorf("no counters loaded")
331321
}
332322

333323
minerLogger.Info().Msgf("Start sniffing %s", device)
@@ -343,7 +333,7 @@ func Start(period time.Duration) (DataChannel, error) {
343333
for !IsSniffing() {
344334
select {
345335
case <-internalEventChannel: // error case
346-
return nil, fmt.Errorf("Something bad happened")
336+
return nil, fmt.Errorf("something bad happened")
347337
default:
348338
// pass
349339
}
@@ -391,9 +381,3 @@ func fileExists(name string) bool {
391381
}
392382
return true
393383
}
394-
395-
// Main ===================================================================== //
396-
// ========================================================================== //
397-
// ========================================================================== //
398-
399-
func main() {}

miner/offline.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func sniffOffline(packetChan chan gopacket.Packet,
2727
for {
2828
select {
2929
// manage events
30-
case e, _ := <-internalEventChannel:
30+
case e := <-internalEventChannel:
3131
switch e {
3232
case STOP:
3333
// the counters are stopped

miner/online.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ func sniffOnline(packetChan chan gopacket.Packet,
6969
data DataChannel) error {
7070

7171
// set the flush tick
72-
tick := time.Tick(period)
72+
tick := time.NewTicker(period)
73+
// tick := time.Tick(period)
7374

7475
// now we are sniffing!
7576
minerLogger.Debug().Msgf("Sniffing interface...")
@@ -81,12 +82,12 @@ func sniffOnline(packetChan chan gopacket.Packet,
8182
for {
8283
select {
8384
// periodic flush
84-
case st := <-tick:
85+
case st := <-tick.C:
8586
sourceTime.Set(st)
8687
dispatcher.terminate()
8788
data <- dispatcher.flushAll()
8889
// manage events
89-
case e, _ := <-internalEventChannel:
90+
case e := <-internalEventChannel:
9091
switch e {
9192
case STOP:
9293
// the counters are stopped

0 commit comments

Comments
 (0)