···78787979 switch action {
8080 case Subscribe:
8181- s.handleSubscribe(peer)
8181+ s.handleSubscribe(&peer)
8282 case Unsubscribe:
8383- s.handleUnsubscribe(peer)
8383+ s.handleUnsubscribe(&peer)
8484 case Publish:
8585- s.handlePublish(peer)
8585+ s.handlePublish(&peer)
8686 default:
8787 slog.Error("unknown action", "action", action, "peer", peer.addr())
8888 writeStatus(Error, "unknown action", peer.conn)
8989 }
9090}
91919292-func (s *Server) handleSubscribe(peer peer) {
9292+func (s *Server) handleSubscribe(peer *peer) {
9393 // subscribe the peer to the topic
9494- s.subscribePeerToTopic(&peer)
9494+ s.subscribePeerToTopic(peer)
95959696 // keep handling the peers connection, getting the action from the peer when it wishes to do something else.
9797 // once the peers connection ends, it will be unsubscribed from all topics and returned
9898 for {
9999- action, err := readAction(peer)
9999+ action, err := readAction(*peer)
100100 if err != nil {
101101 var neterr net.Error
102102 if errors.As(err, &neterr) && neterr.Timeout() {
···106106 // TODO: see if there's a way to check if the peers connection has been ended etc
107107 slog.Error("failed to read action from subscriber", "error", err, "peer", peer.addr())
108108109109- s.unsubscribePeerFromAllTopics(peer)
109109+ s.unsubscribePeerFromAllTopics(*peer)
110110111111 return
112112 }
113113114114 switch action {
115115 case Subscribe:
116116- s.subscribePeerToTopic(&peer)
116116+ s.subscribePeerToTopic(peer)
117117 case Unsubscribe:
118118 s.handleUnsubscribe(peer)
119119 default:
···163163 _ = peer.connOperation(op, "subscribe peer to topic")
164164}
165165166166-func (s *Server) handleUnsubscribe(peer peer) {
166166+func (s *Server) handleUnsubscribe(peer *peer) {
167167 op := func(conn net.Conn) error {
168168 // get the topics the peer wishes to unsubscribe from
169169 dataLen, err := dataLength(conn)
···193193 return nil
194194 }
195195196196- s.unsubscribeToTopics(peer, topics)
196196+ s.unsubscribeToTopics(*peer, topics)
197197 writeStatus(Unsubscribed, "", conn)
198198199199 return nil
···207207 data []byte
208208}
209209210210-func (s *Server) handlePublish(peer peer) {
210210+func (s *Server) handlePublish(peer *peer) {
211211 for {
212212 var message *messageToSend
213213···338338 return nil
339339}
340340341341+// TODO: work out why this can't take a pointer to the peer
341342func readAction(peer peer) (Action, error) {
342343 var action Action
343344 op := func(conn net.Conn) error {