Skip to content

Commit

Permalink
Add documentation and fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
MariemBaccari committed Oct 10, 2023
1 parent 25977d0 commit f853897
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 13 deletions.
5 changes: 3 additions & 2 deletions be1-go/channel/lao/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -709,9 +709,10 @@ func (c *Channel) createAndSendLAOGreet() error {
peer := messagedata.Peer{
Address: info.ClientAddress,
}
if !slices.Contains(peers, peer) {
peers = append(peers, peer)
if slices.Contains(peers, peer) {
continue
}
peers = append(peers, peer)
}

msgData := messagedata.LaoGreet{
Expand Down
2 changes: 1 addition & 1 deletion be1-go/configServer1.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"client-port" : 9000,
"server-port" : 9001,
"auth-port" : 9100,
"other-servers": ["localhost:9003"]
"other-servers": []
}
4 changes: 3 additions & 1 deletion be1-go/configServer2.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
"client-port" : 9002,
"server-port" : 9003,
"auth-port" : 9101,
"other-servers": ["localhost:9001"]
"other-servers": [
"localhost:9001"
]
}
4 changes: 4 additions & 0 deletions be1-go/hub/standard_hub/hub_state/channels_by_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,29 @@ type ChannelsById struct {
table map[string]channel.Channel
}

// NewChannelsById creates a new ChannelsById structure
func NewChannelsById() ChannelsById {
return ChannelsById{
table: make(map[string]channel.Channel),
}
}

// Add adds a channel to the table
func (c *ChannelsById) Add(channelId string, channel channel.Channel) {
c.Lock()
defer c.Unlock()
c.table[channelId] = channel
}

// GetChannel returns a channel from the table if it exists, otherwise it returns false and nil
func (c *ChannelsById) GetChannel(channelId string) (channel.Channel, bool) {
c.RLock()
defer c.RUnlock()
channel, ok := c.table[channelId]
return channel, ok
}

// GetAll returns a copy of the table
func (c *ChannelsById) GetAll() map[string]channel.Channel {
c.RLock()
defer c.RUnlock()
Expand Down
5 changes: 5 additions & 0 deletions be1-go/hub/standard_hub/hub_state/ids_by_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ type IdsByChannel struct {
table map[string][]string
}

// NewIdsByChannel creates a new IdsByChannel structure
func NewIdsByChannel() IdsByChannel {
return IdsByChannel{
table: make(map[string][]string),
}
}

// Add adds a message id to the table
func (i *IdsByChannel) Add(channel string, id string) {
i.Lock()
defer i.Unlock()
Expand All @@ -32,12 +34,14 @@ func (i *IdsByChannel) Add(channel string, id string) {
}
}

// AddAll adds a slice of message ids to the table
func (i *IdsByChannel) AddAll(channel string, ids []string) {
i.Lock()
defer i.Unlock()
i.table[channel] = append(i.table[channel], ids...)
}

// GetAll returns a copy of the table
func (i *IdsByChannel) GetAll() map[string][]string {
i.RLock()
defer i.RUnlock()
Expand All @@ -46,6 +50,7 @@ func (i *IdsByChannel) GetAll() map[string][]string {
return tableCopy
}

// IsEmpty returns true if the table is empty, otherwise it returns false
func (i *IdsByChannel) IsEmpty() bool {
i.RLock()
defer i.RUnlock()
Expand Down
5 changes: 5 additions & 0 deletions be1-go/hub/standard_hub/hub_state/peers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,22 @@ type Peers struct {
peersGreeted []string
}

// NewPeers creates a new Peers structure
func NewPeers() Peers {
return Peers{
peersInfo: make(map[string]method.ServerInfo),
peersGreeted: make([]string, 0),
}
}

// AddPeerInfo adds a peer's info to the table
func (p *Peers) AddPeerInfo(socketId string, info method.ServerInfo) {
p.Lock()
defer p.Unlock()
p.peersInfo[socketId] = info
}

// AddPeerGreeted adds a peer's socket ID to the slice of peers greeted
func (p *Peers) AddPeerGreeted(socketId string) {
p.Lock()
defer p.Unlock()
Expand All @@ -37,6 +40,7 @@ func (p *Peers) AddPeerGreeted(socketId string) {
p.peersGreeted = append(p.peersGreeted, socketId)
}

// GetAllPeersInfo returns a copy of the peers' info slice
func (p *Peers) GetAllPeersInfo() []method.ServerInfo {
p.RLock()
defer p.RUnlock()
Expand All @@ -47,6 +51,7 @@ func (p *Peers) GetAllPeersInfo() []method.ServerInfo {
return peersInfo
}

// IsPeerGreeted returns true if the peer was greeted, otherwise it returns false
func (p *Peers) IsPeerGreeted(socketId string) bool {
p.RLock()
defer p.RUnlock()
Expand Down
18 changes: 9 additions & 9 deletions be1-go/hub/standard_hub/mod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -876,13 +876,13 @@ func Test_Handle_Answer(t *testing.T) {
answerBisBuf, err := json.Marshal(serverAnswerBis)
require.NoError(t, err)

hub.queries.setQueryState(1, false)
hub.queries.SetQueryState(1, false)
query := method.GetMessagesById{
Base: query.Base{},
ID: 1,
Params: nil,
}
hub.queries.addQuery(1, query)
hub.queries.AddQuery(1, query)
sock := &fakeSocket{}

hub.handleMessageFromClient(&socket.IncomingMessage{
Expand All @@ -891,21 +891,21 @@ func Test_Handle_Answer(t *testing.T) {
})
require.Error(t, sock.err, "rpc message sent by a client should be a query")
sock.err = nil
require.False(t, *hub.queries.getQueryState(1))
require.False(t, *hub.queries.GetQueryState(1))

hub.handleMessageFromServer(&socket.IncomingMessage{
Socket: sock,
Message: resultBuf,
})
require.NoError(t, sock.err)
require.False(t, *hub.queries.getQueryState(1))
require.False(t, *hub.queries.GetQueryState(1))

hub.handleMessageFromServer(&socket.IncomingMessage{
Socket: sock,
Message: answerBuf,
})
require.NoError(t, sock.err)
require.True(t, *hub.queries.getQueryState(1))
require.True(t, *hub.queries.GetQueryState(1))

hub.handleMessageFromServer(&socket.IncomingMessage{
Socket: sock,
Expand Down Expand Up @@ -1192,8 +1192,8 @@ func Test_Create_LAO_GetMessagesById_Result(t *testing.T) {
Params: missingMessages,
}

hub.queries.setQueryState(1, false)
hub.queries.addQuery(1, getMessagesByIdQuery)
hub.queries.SetQueryState(1, false)
hub.queries.AddQuery(1, getMessagesByIdQuery)

ans := struct {
JSONRPC string `json:"jsonrpc"`
Expand Down Expand Up @@ -1295,8 +1295,8 @@ func Test_Create_LAO_GetMessagesById_Wrong_MessageID(t *testing.T) {
Params: missingMessages,
}

hub.queries.setQueryState(1, false)
hub.queries.addQuery(1, getMessagesByIdQuery)
hub.queries.SetQueryState(1, false)
hub.queries.AddQuery(1, getMessagesByIdQuery)

ans := struct {
JSONRPC string `json:"jsonrpc"`
Expand Down

0 comments on commit f853897

Please sign in to comment.