kaspad/network/connmanager/connection_set.go
stasatdaglabs 8a4ece1101
[NOD-1223] Reorganize project (#868)
* [NOD-1223] Move all network stuff into a new network package.

* [NOD-1223] Delete the unused package testutil.

* [NOD-1223] Move infrastructure stuff into a new instrastructure package.

* [NOD-1223] Move domain stuff into a new domain package.
2020-08-13 17:27:25 +03:00

31 lines
729 B
Go

package connmanager
import (
"github.com/kaspanet/kaspad/network/netadapter"
)
type connectionSet map[string]*netadapter.NetConnection
func (cs connectionSet) add(connection *netadapter.NetConnection) {
cs[connection.Address()] = connection
}
func (cs connectionSet) remove(connection *netadapter.NetConnection) {
delete(cs, connection.Address())
}
func (cs connectionSet) get(address string) (*netadapter.NetConnection, bool) {
connection, ok := cs[address]
return connection, ok
}
func convertToSet(connections []*netadapter.NetConnection) connectionSet {
connSet := make(connectionSet, len(connections))
for _, connection := range connections {
connSet[connection.Address()] = connection
}
return connSet
}