Documentation ¶
Overview ¶
This package handles the behaviours of the exercise 2 of the htwsaar lesson
Index ¶
- Constants
- func ChooseThreeNeighbors(localNodeId int, allAvailableNodes map[int]server.NetworkServer) (neighbors map[int]server.NetworkServer)
- func ReceiveAndParseIncomingProtobufMessageToChannel(conn net.Conn, c chan *protobuf.MessageTwo)
- func ReceiveAndParseIncomingProtoufMessage(conn net.Conn) *protobuf.MessageTwo
- func SendProtobufApplicationMessage(sourceServer, destinationServer server.NetworkServer, sourceServerId int, ...) error
- func SendProtobufControlMessage(sourceServer, destinationServer server.NetworkServer, ...) error
- func StartController(localNode server.NetworkServer, allNodes map[int]server.NetworkServer, ...)
- func StartIndependentNode(localNodeId int, customerNode bool, ...)
- type CompanyNode
- func (companyNode *CompanyNode) AddRegularCustomer(customerId int, serverObjectInformation server.NetworkServer, override bool) error
- func (companyNode CompanyNode) AdvertisingBudget() int
- func (companyNode CompanyNode) CompanyId() int
- func (companyNode *CompanyNode) InitAdvertisingBudget()
- func (companyNode *CompanyNode) InitAdvertisingBudgetWithThreashold(threshold int)
- func (companyNode CompanyNode) IsRegularCustomer(customerId int) bool
- func (companyNode CompanyNode) Product() string
- func (companyNode CompanyNode) RegularCustomers() map[int]server.NetworkServer
- func (companyNode *CompanyNode) SetAdvertisingBudget(advertisingBudget int)
- func (companyNode *CompanyNode) SetCompanyId(companyId int)
- func (companyNode *CompanyNode) SetProduct(product string)
- func (companyNode *CompanyNode) SetRegularCustomers(regularCustomers map[int]server.NetworkServer)
- func (companyNode CompanyNode) String() string
- type CustomerNode
- func (customerNode CustomerNode) CustomerId() int
- func (customerNode CustomerNode) Friends() map[int]server.NetworkServer
- func (customerNode CustomerNode) HeardAdvertisementsByCompanyId(companyId int) int
- func (customerNode CustomerNode) HeardFriendBuyedItemByCompanyId(companyId int) int
- func (customerNode *CustomerNode) IncreaseHeardAdvertisementsByCompanyId(companyId int)
- func (customerNode *CustomerNode) IncreaseHeardFriendBuyedItemByCompanyId(companyId int)
- func (customerNode *CustomerNode) SetCustomerId(customerId int)
- func (customerNode *CustomerNode) SetFriends(friends map[int]server.NetworkServer)
- func (customerNode CustomerNode) String() string
- func (customerNode CustomerNode) WouldTheCustomerBuyProductFromCompanyWithId(companyId int) bool
Constants ¶
const ( THRESHOLD_BUY_WHEN_ADVERTISEMENT_HEARD = 5 THRESHOLD_BUY_WHEN_FRIED_TELLS_HE_BUYED = 8 )
const (
ADVERTISING_BUGDET_MAXIMUM = 10
)
Variables ¶
This section is empty.
Functions ¶
func ChooseThreeNeighbors ¶
func ChooseThreeNeighbors(localNodeId int, allAvailableNodes map[int]server.NetworkServer) (neighbors map[int]server.NetworkServer)
The chooseThreeNeighbors function uses the allAvailableNodes map to return another map that contains 3 nodes at the most. It calls os.Exit(1) if only one node is available in the allAvailableNodes map.
func ReceiveAndParseIncomingProtobufMessageToChannel ¶
func ReceiveAndParseIncomingProtobufMessageToChannel(conn net.Conn, c chan *protobuf.MessageTwo)
This function uses a established connection to parse the data there to the protobuf message. The result gets assigned to the channel instead of returning it.
func ReceiveAndParseIncomingProtoufMessage ¶
func ReceiveAndParseIncomingProtoufMessage(conn net.Conn) *protobuf.MessageTwo
This function uses a established connection to parse the data there to the protobuf message and returns it.
func SendProtobufApplicationMessage ¶
func SendProtobufApplicationMessage(sourceServer, destinationServer server.NetworkServer, sourceServerId int, messageContent string, isCustomer bool) error
This function sends a application message to the neighbor with the given targetId. If the id does not exists, it just returns and does nothing.
func SendProtobufControlMessage ¶
func SendProtobufControlMessage(sourceServer, destinationServer server.NetworkServer, sourceServerId, controlType int, messageContent string, isCustomer bool) error
This function sends a control message to the node with the given targetId. If the id does not exists, it just returns and does nothing.
func StartController ¶
func StartController(localNode server.NetworkServer, allNodes map[int]server.NetworkServer, messageContent string)
The controller is used to control the independent nodes. He can initialize or shutdown the nodes.
func StartIndependentNode ¶
func StartIndependentNode(localNodeId int, customerNode bool, allAvailableNodes, neighborNodes map[int]server.NetworkServer)
With this function an node that interacts independently gets started. He can be controlled with a controller.
Types ¶
type CompanyNode ¶
type CompanyNode struct { server.NetworkServer // contains filtered or unexported fields }
This node represents a compyna for the exercise 2. The company tries to sell a product and starts publicity campaigns in form of adverdisements. These advertisements are sent to all neighbors which are customers. Each company got only a specifiy budget to do adverdisements, where earch campain reduces the budget. If a customer buys a product, he will be inserted to a list of regular customers and receives now all advertisements. That means, that the customer is now a neighbor of the company.
func NewCompanyNodeWithServerObject ¶
func NewCompanyNodeWithServerObject(serverObject server.NetworkServer) CompanyNode
func (*CompanyNode) AddRegularCustomer ¶
func (companyNode *CompanyNode) AddRegularCustomer(customerId int, serverObjectInformation server.NetworkServer, override bool) error
Add a customer to the regular customers. Returns a error if the customer is already available.
func (CompanyNode) AdvertisingBudget ¶
func (companyNode CompanyNode) AdvertisingBudget() int
Return the budget for the advertisements
func (CompanyNode) CompanyId ¶
func (companyNode CompanyNode) CompanyId() int
Return the company id.
func (*CompanyNode) InitAdvertisingBudget ¶
func (companyNode *CompanyNode) InitAdvertisingBudget()
Sets the budget to a random value with the following range: [0, ADVERTISING_BUDGET_MAXIMUM)
func (*CompanyNode) InitAdvertisingBudgetWithThreashold ¶
func (companyNode *CompanyNode) InitAdvertisingBudgetWithThreashold(threshold int)
Sets the budget to a random value with the following range: [0, threshold)
func (CompanyNode) IsRegularCustomer ¶
func (companyNode CompanyNode) IsRegularCustomer(customerId int) bool
Check if the customer with the given id is a regular customer.
func (CompanyNode) Product ¶
func (companyNode CompanyNode) Product() string
Return the product name
func (CompanyNode) RegularCustomers ¶
func (companyNode CompanyNode) RegularCustomers() map[int]server.NetworkServer
Return the map of regular customers
func (*CompanyNode) SetAdvertisingBudget ¶
func (companyNode *CompanyNode) SetAdvertisingBudget(advertisingBudget int)
Set the budget for the advertiesements
func (*CompanyNode) SetCompanyId ¶
func (companyNode *CompanyNode) SetCompanyId(companyId int)
Set the value of the company id
func (*CompanyNode) SetProduct ¶
func (companyNode *CompanyNode) SetProduct(product string)
Set the name of the product
func (*CompanyNode) SetRegularCustomers ¶
func (companyNode *CompanyNode) SetRegularCustomers(regularCustomers map[int]server.NetworkServer)
Set the map of regular customers
func (CompanyNode) String ¶
func (companyNode CompanyNode) String() string
The string representation of this type.
type CustomerNode ¶
type CustomerNode struct { server.NetworkServer // contains filtered or unexported fields }
This node represents a customer for exercise 2. The customer gets informed from companies about new products and buys one, if he hears the advertisement from a company. He also buys the product if enough friends told him, that they buyed the product already.
func NewCustomerNode ¶
func NewCustomerNode() CustomerNode
Creates a new CustomerNode with initialized values.
func NewCustomerNodeWithServerObject ¶
func NewCustomerNodeWithServerObject(serverObject server.NetworkServer) CustomerNode
Creates a new CustomerNode with initialized values, where the server object is set instead of setting an empty one.
func (CustomerNode) CustomerId ¶
func (customerNode CustomerNode) CustomerId() int
Returns the customer id
func (CustomerNode) Friends ¶
func (customerNode CustomerNode) Friends() map[int]server.NetworkServer
Returns the friend map
func (CustomerNode) HeardAdvertisementsByCompanyId ¶
func (customerNode CustomerNode) HeardAdvertisementsByCompanyId(companyId int) int
Returns the number of heared advertisements of the specific company.
func (CustomerNode) HeardFriendBuyedItemByCompanyId ¶
func (customerNode CustomerNode) HeardFriendBuyedItemByCompanyId(companyId int) int
Returns the number of friends that buyed a product of the specified company.
func (*CustomerNode) IncreaseHeardAdvertisementsByCompanyId ¶
func (customerNode *CustomerNode) IncreaseHeardAdvertisementsByCompanyId(companyId int)
Increases the number of heared advertisements of the specific company by one.
func (*CustomerNode) IncreaseHeardFriendBuyedItemByCompanyId ¶
func (customerNode *CustomerNode) IncreaseHeardFriendBuyedItemByCompanyId(companyId int)
Increases the number of friends that buyed a product of the specified company by one.
func (*CustomerNode) SetCustomerId ¶
func (customerNode *CustomerNode) SetCustomerId(customerId int)
Set the customer id
func (*CustomerNode) SetFriends ¶
func (customerNode *CustomerNode) SetFriends(friends map[int]server.NetworkServer)
Set the friend map
func (CustomerNode) String ¶
func (customerNode CustomerNode) String() string
The string representation
func (CustomerNode) WouldTheCustomerBuyProductFromCompanyWithId ¶
func (customerNode CustomerNode) WouldTheCustomerBuyProductFromCompanyWithId(companyId int) bool
Checks if the customer would buy a product of the specifie company. It will check the values of the advertisements and the recommendations of the friends.