Skip to content

Commit f19889f

Browse files
author
Alfonso Acosta
committed
Reduce garbage
1 parent 5c02dfc commit f19889f

File tree

1 file changed

+9
-21
lines changed

1 file changed

+9
-21
lines changed

probe/endpoint/conntrack.go

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,9 @@ type meta struct {
5454

5555
type flow struct {
5656
XMLName xml.Name `xml:"flow"`
57-
Metas []meta `xml:"meta"`
5857
Type string `xml:"type,attr"`
5958

60-
Original, Reply, Independent *meta `xml:"-"`
59+
Original, Reply, Independent meta `xml:"-"`
6160
}
6261

6362
type conntrack struct {
@@ -220,17 +219,6 @@ func (c *conntrackWalker) run() {
220219
}
221220
}
222221

223-
func makeEmptyFlow() flow {
224-
var f flow
225-
metas := make([]meta, 3)
226-
f.Metas = metas
227-
// TODO: do we really need the direction/protocol type when not using XML?
228-
f.Original = &metas[0]
229-
f.Reply = &metas[1]
230-
f.Independent = &metas[2]
231-
return f
232-
}
233-
234222
func getUntaggedLine(reader *bufio.Reader) (string, error) {
235223
// TODO: read bytes?
236224
line, err := reader.ReadString('\n')
@@ -246,9 +234,9 @@ func getUntaggedLine(reader *bufio.Reader) (string, error) {
246234

247235
func decodeStreamedFlow(reader *bufio.Reader) (flow, error) {
248236
var (
249-
// TODO: use ints where possible?
250-
omit [10]string
251-
f = makeEmptyFlow()
237+
// TODO: use []byte/int where possible?
238+
omit [4]string
239+
f flow
252240
)
253241

254242
// Examples:
@@ -329,7 +317,7 @@ func (c *conntrackWalker) existingConnections() ([]flow, error) {
329317
reader := bufio.NewReader(stdout)
330318
var result []flow
331319
for {
332-
f, err := readDumpedFlow(reader)
320+
f, err := decodeDumpedFlow(reader)
333321
if err != nil {
334322
if err == io.EOF {
335323
break
@@ -342,11 +330,11 @@ func (c *conntrackWalker) existingConnections() ([]flow, error) {
342330
return result, nil
343331
}
344332

345-
func readDumpedFlow(reader *bufio.Reader) (flow, error) {
333+
func decodeDumpedFlow(reader *bufio.Reader) (flow, error) {
346334
var (
347-
// TODO: use byteslices where possible?
348-
omit [10]string
349-
f = makeEmptyFlow()
335+
// TODO: use int/[]byte where possible?
336+
omit [4]string
337+
f flow
350338
)
351339

352340
// Example:

0 commit comments

Comments
 (0)