# ServerObserver

<a id="serverobserver"></a>

# ServerObserver

```cpp
#include <icy/turn/server/server.h>

struct ServerObserver
```

[Defined in src/turn/include/icy/turn/server/server.h:96](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/server/server.h#L96)

Observer interface that the application must implement to participate in server-side allocation management and authentication.

The observer is responsible for enforcing per-user allocation quotas and bandwidth limits. Implementations may perform authentication synchronously (returning Authorized/NotAuthorized immediately) or asynchronously (returning Authenticating and calling handleRequest() again later).

## Public Methods

| Return | Name | Description |
|--------|------|-------------|
| `void` | [`onServerAllocationCreated`](#onserverallocationcreated) `virtual` | Called after a new allocation is successfully created. |
| `void` | [`onServerAllocationRemoved`](#onserverallocationremoved) `virtual` | Called just before an allocation is destroyed (expired, deleted, or server stopped). |
| [`AuthenticationState`](https://auscaster.com/icey/docs/api-reference/icy-turn.md#authenticationstate) | [`authenticateRequest`](#authenticaterequest-1) `virtual` | Authenticates an incoming STUN request using the long-term credential mechanism (RFC 5389 section 10.2). Return Authorized to proceed, NotAuthorized to reject with a 401, QuotaReached to reject with a 486, or Authenticating to defer until the result is available asynchronously. |

---

<a id="onserverallocationcreated"></a>

### onServerAllocationCreated

`virtual`

```cpp
virtual void onServerAllocationCreated(Server * server, IAllocation * alloc)
```

[Defined in src/turn/include/icy/turn/server/server.h:101](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/server/server.h#L101)

Called after a new allocation is successfully created.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `server` | [`Server`](https://auscaster.com/icey/docs/api-reference/icy-turn-Server.md#server-7) * | The server that owns the allocation. |
| `alloc` | [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) * | The newly created allocation (lifetime managed by the server). |

---

<a id="onserverallocationremoved"></a>

### onServerAllocationRemoved

`virtual`

```cpp
virtual void onServerAllocationRemoved(Server * server, IAllocation * alloc)
```

[Defined in src/turn/include/icy/turn/server/server.h:106](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/server/server.h#L106)

Called just before an allocation is destroyed (expired, deleted, or server stopped).

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `server` | [`Server`](https://auscaster.com/icey/docs/api-reference/icy-turn-Server.md#server-7) * | The server that owned the allocation. |
| `alloc` | [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) * | The allocation being removed; do not delete this pointer. |

---

<a id="authenticaterequest-1"></a>

### authenticateRequest

`virtual`

```cpp
virtual AuthenticationState authenticateRequest(Server * server, Request & request)
```

[Defined in src/turn/include/icy/turn/server/server.h:115](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/server/server.h#L115)

Authenticates an incoming STUN request using the long-term credential mechanism (RFC 5389 section 10.2). Return Authorized to proceed, NotAuthorized to reject with a 401, QuotaReached to reject with a 486, or Authenticating to defer until the result is available asynchronously. 
#### Returns
An AuthenticationState indicating how to proceed.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `server` | [`Server`](https://auscaster.com/icey/docs/api-reference/icy-turn-Server.md#server-7) * | The server receiving the request. |
| `request` | [`Request`](https://auscaster.com/icey/docs/api-reference/icy-turn-Request.md#request-14) & | The STUN request to authenticate. |
