-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstruct_main_routines.go
67 lines (47 loc) · 1.15 KB
/
construct_main_routines.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package ipshuffle
import (
"io"
"bufio"
"os"
"fmt"
"strings"
)
var (
QUEUE_SIZE int32 = 100000000
)
//heavily inspired by
//https://github.com/stanford-esrg/lzr/blob/master/construct_main_routines.go#L53
func ConstructIncomingRoutine( num_ports int ) chan []string {
//routine to read in from ZMap
incoming := make(chan []string, QUEUE_SIZE)
go func() {
var IP_Group []string
reader := bufio.NewReader(os.Stdin)
for {
//Read from ZIterate
ip, err := reader.ReadString(byte('\n'))
if err != nil && err == io.EOF {
fmt.Fprintln(os.Stderr,"Finished Reading IPShuffle Input")
close(incoming)
return
}
ip = strings.TrimSuffix(ip, "\n")
//put lists of num_ports
IP_Group = append(IP_Group,ip)
//must grow to correct size
if len(IP_Group) < num_ports {
continue
} else {
//send off the slice
incoming <- IP_Group
//remove the first element and shift over by 1
IP_Group = IP_Group[1:num_ports]
}
}
}()
return incoming
}
func ConstructWritingQueue() chan []string {
writingQueue := make(chan []string, QUEUE_SIZE)
return writingQueue
}