Agent server
netsecgame.game.agent_server.AgentServer(actions_queue, agent_response_queues, max_connections)
Bases: Protocol
Class used for serving the agents when connecting to the game run by the GameCoordinator.
Attributes:
| Name | Type | Description |
|---|---|---|
actions_queue |
Queue
|
Queue for actions from agents. |
answers_queues |
dict
|
Mapping of agent addresses to their response queues. |
max_connections |
int
|
Maximum allowed concurrent agent connections. |
current_connections |
int
|
Current number of connected agents. |
logger |
Logger
|
Logger for the AgentServer. |
Initialize the AgentServer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
actions_queue
|
Queue
|
Queue for actions from agents. |
required |
agent_response_queues
|
dict
|
Mapping of agent addresses to their response queues. |
required |
max_connections
|
int
|
Maximum allowed concurrent agent connections. |
required |
Source code in netsecgame/game/agent_server.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
__call__(reader, writer)
async
Allow the server instance to be called as a coroutine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reader
|
StreamReader
|
Stream reader for the agent. |
required |
writer
|
StreamWriter
|
Stream writer for the agent. |
required |
Source code in netsecgame/game/agent_server.py
116 117 118 119 120 121 122 123 124 | |
handle_agent_quit(peername)
async
Helper function to handle agent disconnection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
peername
|
tuple
|
The address of the disconnecting agent. |
required |
Source code in netsecgame/game/agent_server.py
31 32 33 34 35 36 37 38 39 40 41 | |
handle_new_agent(reader, writer)
async
Handle a new agent connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reader
|
StreamReader
|
Stream reader for the agent. |
required |
writer
|
StreamWriter
|
Stream writer for the agent. |
required |
Source code in netsecgame/game/agent_server.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |