From 19487be77307ef644195c75c034f6f5cc5038c13 Mon Sep 17 00:00:00 2001 From: Jim Colderwood Date: Thu, 2 May 2024 10:11:16 +0100 Subject: [PATCH] Mutex should be pointer, comments added. --- ripv2/ripv2.go | 10 +++++++--- ripv2/routes.go | 9 +++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/ripv2/ripv2.go b/ripv2/ripv2.go index f3c33c1..875e430 100644 --- a/ripv2/ripv2.go +++ b/ripv2/ripv2.go @@ -14,11 +14,14 @@ import ( ) func New() Message { - var message Message - message.RIP = make([]RIP, 25) - return message + return Message{ + RIP: make([]RIP, 25), + } } +/* Parse the raw data packet + * Store the serialised data in the Message slice + */ func (m *Message) MParse(b *[]byte, n int) error { if n == 0 { return errors.New("can't parse empty data") @@ -59,6 +62,7 @@ func (m *Message) MParse(b *[]byte, n int) error { return nil } +/* Listen for network packets */ func (m *Message) Run(c *config.Config, callback func(*Routes)) error { iface := net.Interface{ Name: c.MulticastInterface, diff --git a/ripv2/routes.go b/ripv2/routes.go index e5b4f56..120954f 100644 --- a/ripv2/routes.go +++ b/ripv2/routes.go @@ -10,7 +10,7 @@ import ( type Routes struct { Routes map[string]Route - sync.Mutex + *sync.Mutex } type Route struct { @@ -23,9 +23,10 @@ type Route struct { } func Init() *Routes { - var routes Routes - routes.Routes = make(map[string]Route, 25) - return &routes + return &Routes{ + Routes: make(map[string]Route, 25), + Mutex: new(sync.Mutex), + } } func (r *Routes) append(route Route) {