### Install Build Dependencies on Debian Source: https://github.com/drachtio/drachtio-server/blob/main/README.md Installs necessary libraries for building drachtio-server on Debian-based systems. ```bash sudo apt install libcurl4-openssl-dev libboost-all-dev ``` -------------------------------- ### Example Routing URL with Query Parameters Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/proxying-and-routing.md Illustrates an example URL for an HTTP routing query, including common parameters derived from SIP headers and request details. ```http http://routing-server:8080/?method=INVITE&domain=example.com&uriUser=bob&uri=sip:bob%40example.com&protocol=udp ``` -------------------------------- ### Gauge Manipulation Examples Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/metrics-and-monitoring.md Examples of incrementing, decrementing, and setting gauge values. Includes setting a gauge to the current time. ```cpp STATS_GAUGE_INCREMENT("drachtio_stable_dialogs"); STATS_GAUGE_SET("drachtio_stable_dialogs", 42); STATS_GAUGE_DECREMENT("drachtio_stable_dialogs"); STATS_GAUGE_SET_TO_CURRENT_TIME("drachtio_time_started"); ``` -------------------------------- ### SIP Message Notification Example Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/client-server-protocol.md An example demonstrating the structure of a SIP message notification, including the client message ID, SIP message, and metadata. ```text 1234567890 INVITE sip:alice@example.com SIP/2.0 Via: SIP/2.0/UDP 192.168.1.1:5060 From: sip:bob@example.com;tag=abc123 To: sip:alice@example.com Call-ID: call-123@example.com CSeq: 1 INVITE ... --- network|INVITE sip:alice@example.com SIP/2.0...|udp|192.168.1.1|5060|1234567890 ``` -------------------------------- ### TimerQueue Usage Example Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/advanced-features.md Demonstrates how to create a TimerQueue, add a callback function with user data, and remove it. ```cpp TimerQueue queue(root, "my-timer"); void myCallback(void* arg) { int value = *(int*)arg; printf("Timer fired with value %d\n", value); } int myValue = 42; TimerEventHandle handle = queue.add(myCallback, &myValue, 5000); // 5 seconds // Later, cancel if needed: queue.remove(handle); ``` -------------------------------- ### Record-Route Header Example Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/proxying-and-routing.md An example of a Record-Route header inserted by drachtio when record-routing is enabled. This ensures subsequent in-dialog requests are routed through drachtio. ```text Record-Route: ``` -------------------------------- ### Start Drachtio with Prometheus Metrics Enabled Source: https://github.com/drachtio/drachtio-server/blob/main/docs/prometheus.md Start the Drachtio server and expose Prometheus metrics on port 9099. This command is used to enable the metrics endpoint for scraping. ```bash ./drachtio --prometheus-scrape-port 9099 -f ../test/drachtio.conf.xml & ``` -------------------------------- ### DrachtioController run() Method Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/classes-and-types.md Starts the main event loop of the Drachtio server. This is a blocking call. ```cpp void run() ``` -------------------------------- ### Histogram Creation and Observation Example Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/metrics-and-monitoring.md Create a histogram with custom bucket boundaries and observe values to track distributions. ```cpp StatsCollector::BucketBoundaries buckets = {0.1, 0.5, 1.0, 2.0, 5.0}; statsCollector.histogramCreate("response_time_seconds", "Response time distribution", buckets); ``` -------------------------------- ### Run Drachtio Server Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/README.md Examples of running drachtio-server with default configuration, custom configuration file, daemon mode, specifying SIP contacts, and enabling logging. ```bash # With default config ddrachtio # With custom config ddrachtio -f /path/to/config.xml # Daemon mode ddrachtio --daemon -f /path/to/config.xml # Specify SIP contacts ddrachtio --contact "sip:*:5060;transport=udp,tcp" --port 9022 # Enable logging ddrachtio --loglevel info --console ``` -------------------------------- ### Run Drachtio Server as a Daemon Source: https://github.com/drachtio/drachtio-server/blob/main/README.md Starts the drachtio server as a background daemon process. ```bash ./drachtio --daemon ``` -------------------------------- ### JSON SIP Message Format Example Source: https://github.com/drachtio/drachtio-server/blob/main/docs/messages.md An example of the JSON structure representing a SIP INVITE message, including request URI, headers, and payload details. ```js { "request_uri": { "method": "INVITE" ,"version": "SIP/2.0" ,"url": { "scheme": "sip" ,"user": "11" ,"host": "localhost" } } ,"headers": { "via": [ { "protocol": "SIP/2.0/UDP" ,"host": "127.0.0.1" ,"port": "39918" ,"branch": "z9hG4bK-d8754z-ce8b6972d37e5b74-1---d8754z-" ,"rport": "39918" ,"params": ["branch=z9hG4bK-d8754z-ce8b6972d37e5b74-1---d8754z-","rport=39918"] } ] ,"max_forwards": {"count": "70"} ,"from": {"display": "","tag": "f66e7e75","url": {"scheme": "sip","user": "1234","host": "localhost"},"params": ["tag=f66e7e75"]} ,"to": {"display": "","url": {"scheme": "sip","user": "11","host": "localhost"},"params": []} ,"call_id": "MDJiMjA5NzQxNzliMmZiNDJlZjIxNmVhY2I4MTBlZmY" ,"cseq": {"seq": "1","method": "INVITE"} ,"contact": {"display": "","url": {"scheme": "sip","user": "1234","host": "127.0.0.1","port": "39918"},"params": []} } } ``` -------------------------------- ### Install tcmalloc Dependency Source: https://github.com/drachtio/drachtio-server/blob/main/README.md Installs the libgoogle-perftools-dev package required for building drachtio-server with tcmalloc. ```bash sudo apt install libgoogle-perftools-dev ``` -------------------------------- ### parseStartLine Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/api-reference.md Parses the start line of a SIP message to extract the method name and request URI. ```APIDOC ## parseStartLine ### Description Parses the start line of a SIP message to extract the method name and request URI. ### Signature ```cpp sip_method_t parseStartLine(const string& startLine, string& methodName, string& requestUri) ``` ### Parameters #### Input Parameters - **startLine** (const string&) - SIP request line (e.g., `INVITE sip:user@host SIP/2.0`) #### Output Parameters - **methodName** (string&) - Output: Method name as string - **requestUri** (string&) - Output: Request URI ### Returns `sip_method_t` representing the method. ``` -------------------------------- ### Admin Secret Configuration (Command-line) Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/client-server-protocol.md Example of providing the shared secret for admin authentication via a command-line argument. ```bash drachtio --secret shared-secret ``` -------------------------------- ### Console Logging Configuration Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/metrics-and-monitoring.md Configure console logging by specifying the desired log level via the command line. This example sets the log level to 'info'. ```bash drachtio --loglevel info ``` -------------------------------- ### Increment Counter Example Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/metrics-and-monitoring.md Increment a counter by one or by a specified value. Use predefined macros for convenience. ```cpp STATS_COUNTER_INCREMENT("drachtio_sip_requests_in_total"); STATS_COUNTER_INCREMENT("drachtio_sip_requests_in_total", 5); ``` -------------------------------- ### Admin Secret Configuration (Environment Variable) Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/client-server-protocol.md Example of setting the shared secret for admin authentication using an environment variable. ```bash DRACHTIO_ADMIN_SECRET=shared-secret ``` -------------------------------- ### Via Header Example Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/proxying-and-routing.md Illustrates a Via header added by a proxy hop, including IP address, port, and branch identifier. Via headers are crucial for routing responses back through the proxy chain. ```text Via: SIP/2.0/udp 192.168.1.1:5060;branch=z9hG4bK-abcd-1234 ``` -------------------------------- ### Get Application Name Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/client-server-protocol.md Retrieves the application name used for logging and statistics. This is how each client identifies itself to the server. ```cpp bool getAppName(string& strAppName) ``` -------------------------------- ### Blacklist Constructors Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/classes-and-types.md Constructors for initializing the Blacklist class, allowing configuration via direct Redis connection details or Sentinel setup. Used to set up the IP address blacklist with Redis. ```cpp Blacklist(string& redisAddress, unsigned int redisPort, string& redisPassword, string& redisKey, unsigned int refreshSecs = 3600) Blacklist(string& sentinels, string& masterName, string& redisPassword, string& redisKey, unsigned int refreshSecs = 3600) ``` -------------------------------- ### Blacklist Methods Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/classes-and-types.md Methods for starting, stopping, checking blacklist status, and managing the internal thread for updating the blacklist from Redis. Use for controlling the IP blacklist functionality. ```cpp void start() void stop() bool isBlackListed(const char* srcAddress) void threadFunc() ``` -------------------------------- ### Admin Secret Configuration (XML) Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/client-server-protocol.md Example of configuring the shared secret for admin authentication via an XML configuration file. ```xml 127.0.0.1 ``` -------------------------------- ### Cdr Constructor Forms Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/classes-and-types.md Constructors for different types of Call Detail Records (Cdr): Attempt, Start, and Stop. ```cpp CdrAttempt(msg_t* msg, const char* source) CdrStart(msg_t* msg, const char* source, AgentRole_t agentRole) CdrStop(msg_t* msg, const char* source, TerminationReason_t terminationReason) ``` -------------------------------- ### Prometheus Time-Series Queries Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/metrics-and-monitoring.md Examples of Prometheus queries for monitoring Drachtio server metrics like active dialogs, request rates, and call answer times. ```promql # Active dialogs drachtio_stable_dialogs # Requests per second rate(drachtio_sip_requests_in_total[1m]) # P95 call answer time histogram_quantile(0.95, drachtio_call_answer_seconds_in_bucket) # Sofia transaction count drachtio_sofia_server_txns + drachtio_sofia_client_txns ``` -------------------------------- ### Dialog Timing Information Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/dialog-management.md Getters for dialog start, connect, and end times. Methods to set connect and end times are also provided. ```cpp time_t getStartTime() // When dialog started time_t getConnectTime() // When call connected (200 OK) time_t getEndTime() // When call ended void setConnectTime() void setEndTime() ``` -------------------------------- ### Clone drachtio-server Git Repository Source: https://github.com/drachtio/drachtio-server/blob/main/el/README.md Clones the drachtio-server Git repository with a depth of 50 and the main branch. Ensure you have Git installed. ```bash git clone --depth=50 --branch=main git://github.com/davehorton/drachtio-server.git ``` -------------------------------- ### Get Minimum TLS Version Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/advanced-features.md Retrieves the minimum supported TLS version configured for the server. This can be set via an environment variable. ```cpp bool getMinTlsVersion(float& minTlsVersion) ``` -------------------------------- ### Parse SIP Start Line Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/api-reference.md Parses the initial line of a SIP message to extract the method and request URI. Use this to identify the type of SIP request. ```cpp sip_method_t parseStartLine(const string& startLine, string& methodName, string& requestUri) ``` -------------------------------- ### Blacklist Methods Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/classes-and-types.md Provides Redis-backed IP address blacklisting functionality for spam and attack prevention, with methods to start, stop, and check if an IP is blacklisted. ```APIDOC ## Blacklist ### Description Redis-backed IP address blacklist for spam/attack prevention. ### Constructors - `Blacklist(string& redisAddress, unsigned int redisPort, string& redisPassword, string& redisKey, unsigned int refreshSecs = 3600)`: Constructs a Blacklist using a single Redis instance. - `Blacklist(string& sentinels, string& masterName, string& redisPassword, string& redisKey, unsigned int refreshSecs = 3600)`: Constructs a Blacklist using Redis sentinels. ### Methods - `start()`: Starts the blacklist service, initiating background updates from Redis. - `stop()`: Stops the blacklist service. - `isBlackListed(const char* srcAddress)`: Checks if the given IP address is present in the blacklist. - `threadFunc()`: The main function executed by the blacklist's background thread for updating the blacklist from Redis. ``` -------------------------------- ### Build Drachtio Server from Source Source: https://github.com/drachtio/drachtio-server/blob/main/README.md Clones the repository, updates submodules, configures the build, and compiles the drachtio-server executable. ```bash git clone --depth=50 --branch=main https://github.com/drachtio/drachtio-server.git && cd drachtio-server git submodule update --init --recursive ./autogen.sh mkdir build && cd $_ ../configure CPPFLAGS='-DNDEBUG' make sudo make install ``` -------------------------------- ### Make HTTP Request for Routing Decision Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/proxying-and-routing.md Initiates an outbound HTTP request to determine SIP request routing. Supports GET and POST methods with an optional body. ```cpp void makeRequestForRoute(const string& transactionId, const string& httpMethod, const string& httpUrl, const string& body, bool verifyPeer = true) ``` -------------------------------- ### Display Drachtio Server Command Line Options Source: https://github.com/drachtio/drachtio-server/blob/main/README.md Shows all available command-line arguments for configuring and running the drachtio server. ```bash drachtio -h ``` -------------------------------- ### Run Drachtio Server Source: https://github.com/drachtio/drachtio-server/blob/main/README.md Executes the drachtio server. If no configuration file is specified, it defaults to /etc/drachtio.conf.xml. Use -f to specify an alternative config file. ```bash ./drachtio -f ../drachtio.conf.xml ``` -------------------------------- ### DrachtioController Constructor Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/classes-and-types.md Initializes the Drachtio server controller with command-line arguments. ```cpp DrachtioController(int argc, char* argv[]) ``` -------------------------------- ### Prometheus Metric Exposure Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/metrics-and-monitoring.md Example of how a metric with labels is exposed by Prometheus. ```text drachtio_sip_requests_in_total{direction="inbound",protocol="udp"} 42 ``` -------------------------------- ### Get Transport Description Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/api-reference.md Retrieves a string description of a Sofia transport object. ```cpp void getTransportDescription(const tport_t* tp, string& desc) ``` -------------------------------- ### SipDialog Constructor for Incoming INVITE Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/dialog-management.md Constructs a SipDialog for an incoming INVITE request, acting as the UAS (User Agent Server). ```cpp SipDialog(nta_leg_t* leg, nta_incoming_t* irq, sip_t const *sip, msg_t *msg) ``` -------------------------------- ### Enable Prometheus via Configuration File Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/metrics-and-monitoring.md Configure Prometheus metrics scraping within the Drachtio configuration file using the monitoring section. ```xml 127.0.0.1 ``` -------------------------------- ### Get TCP Keepalive Interval Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/advanced-features.md Retrieves the configured interval for TCP keepalive probes. ```cpp unsigned int getTcpKeepaliveInterval() ``` -------------------------------- ### SipDialogController Constructor Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/dialog-management.md Initializes the SipDialogController. Requires a DrachtioController reference and a Sofia clone for event loop management. ```cpp SipDialogController(DrachtioController* pController, su_clone_r* pClone) ``` -------------------------------- ### Prometheus Alerting Examples Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/metrics-and-monitoring.md Defines Prometheus alerting rules for high dialog counts and Prometheus unavailability. ```yaml groups: - name: drachtio rules: - alert: HighDialogCount expr: drachtio_stable_dialogs > 10000 annotations: summary: "Drachtio has {{ $value }} active dialogs" - alert: PrometheusDown expr: up{job="drachtio"} == 0 for: 1m annotations: summary: "Drachtio metrics unavailable" ``` -------------------------------- ### Configure Log Levels via Command-line Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/configuration.md Set the log level for Drachtio and the Sofia-SIP stack using command-line flags. ```bash drachtio --loglevel info --sofia-loglevel 3 ``` -------------------------------- ### Outbound Client Connection Constructor Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/client-server-protocol.md Constructor for initiating outbound connections to client applications for request routing. Requires an ASIO context, parent controller, transaction ID, and remote host/port. ```cpp Client(boost::asio::io_context& io_context, ClientController& controller, const string& transactionId, const string& host, const string& port) ``` -------------------------------- ### Configure TCP/TLS Admin Ports and Secret via Command-line Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/configuration.md Configure the TCP and TLS ports for admin client connections and the admin bind address using command-line flags. ```bash drachtio --port 9022 --tls-port 9023 --secret cymru --admin-address 127.0.0.1 ``` -------------------------------- ### isImmutableHdr Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/api-reference.md Checks if a given SIP header is immutable, meaning it cannot be modified. Examples of immutable headers include Via, From, To, and Call-ID. ```APIDOC ## isImmutableHdr ### Description Checks if a given SIP header is immutable, meaning it cannot be modified. Examples of immutable headers include Via, From, To, and Call-ID. ### Signature ```cpp bool isImmutableHdr(const std::string& hdr) ``` ### Parameters #### Input Parameters - **hdr** (const std::string&) - Header name to check ### Returns `true` if header cannot be modified. ``` -------------------------------- ### Run Leak Reproducer with Plain WS Source: https://github.com/drachtio/drachtio-server/blob/main/test/leak-repro/README.md Executes the leak-tester using WebSocket (WS) transport. Requires specifying the host and port for drachtio. ```bash ./leak-tester --drachtio host:port --transport ws --callee 15083084809 ``` -------------------------------- ### Configure SIP TLS Settings Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/configuration.md Sets up TLS for secure SIP communication by specifying paths to key, certificate, and chain files, as well as DH parameters. Configuration can be done via XML, command-line, or environment variables. ```xml /etc/letsencrypt/live/domain/privkey.pem /etc/letsencrypt/live/domain/cert.pem /etc/letsencrypt/live/domain/chain.pem /var/local/dh4096.pem ``` ```bash drachtio --tls-key /path/to/key --tls-cert /path/to/cert \ --tls-chain /path/to/chain --tls-dh /path/to/dh ``` ```bash DRACHTIO_TLS_KEY=/path/to/key DRACHTIO_TLS_CERT=/path/to/cert DRACHTIO_TLS_CHAIN=/path/to/chain DRACHTIO_TLS_DH=/path/to/dh ``` -------------------------------- ### Configure Log Levels via Environment Variables Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/configuration.md Set environment variables to configure the log levels for Drachtio and the Sofia-SIP stack. ```bash DRACHTIO_LOGLEVEL=info DRACHTIO_SOFIA_LOGLEVEL=3 ``` -------------------------------- ### Get Connection Duration Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/client-server-protocol.md Returns the duration of the current connection in seconds since its establishment. Used for monitoring connection lifecycles. ```cpp int getConnectionDuration() const ``` -------------------------------- ### Build drachtio-server RPMs Source: https://github.com/drachtio/drachtio-server/blob/main/el/README.md Builds the binary RPM packages from the created tar archive. The resulting RPMs will be located in ~/rpmbuild/RPMS. ```bash rpmbuild -ta drachtio.tar.gz ``` -------------------------------- ### Get Session Timer Default Refresher Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/advanced-features.md Retrieves the default refresher selection for session timers (RFC 4028). Can be 'uac' or 'uas'. ```cpp const std::string& getSessionTimerDefaultRefresher() ``` -------------------------------- ### Enable Prometheus via Command Line Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/metrics-and-monitoring.md Enable Prometheus metrics scraping by specifying the scrape port. Can be a port number or an IP address and port. ```bash drachtio --prometheus-scrape-port 8088 drachio --prometheus-scrape-port "0.0.0.0:8088" ``` -------------------------------- ### Configure Aggressive NAT Detection Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/configuration.md Enable more aggressive behavior detection for NAT environments. This can improve reliability in complex network setups. ```xml true ``` -------------------------------- ### Blacklist via Redis (Address/Port) Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/advanced-features.md Initializes the Blacklist feature using a direct Redis server address, port, password, key, and refresh interval. ```cpp Blacklist(string& redisAddress, unsigned int redisPort, string& redisPassword, string& redisKey, unsigned int refreshSecs = 3600) ``` -------------------------------- ### Build the Leak Reproducer Source: https://github.com/drachtio/drachtio-server/blob/main/test/leak-repro/README.md Builds the leak-tester executable from the source code. This is a prerequisite for running the reproducer. ```bash go build -o leak-tester . ``` -------------------------------- ### Cdr Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/classes-and-types.md Call Detail Record for tracking call lifecycle events, including attempt, start, and stop phases with associated reasons and roles. ```APIDOC ## Cdr **File:** `src/cdr.hpp` Call Detail Record for tracking call lifecycle events. ### Enumerations ```cpp enum AgentRole_t { role_undefined = 0, proxy_uac, // Proxy acting as UAC proxy_uas, // Proxy acting as UAS uac, // Client acting as UAC uas // Client acting as UAS }; enum RecordType_t { attempt_record = 0, start_record, stop_record }; enum TerminationReason_t { no_termination = 0, call_rejected, call_canceled, normal_release, session_expired, ackbye, system_initiated_termination, system_error_initiated_termination }; ``` ### Constructors ```cpp CdrAttempt(msg_t* msg, const char* source) CdrStart(msg_t* msg, const char* source, AgentRole_t agentRole) CdrStop(msg_t* msg, const char* source, TerminationReason_t terminationReason) ``` ``` -------------------------------- ### SipTransport Static Methods for Management Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/classes-and-types.md Static methods for managing and retrieving SipTransport configurations. ```cpp static void addTransports(std::shared_ptr config, unsigned int mtu) static std::shared_ptr findTransport(tport_t* tp) static std::shared_ptr findAppropriateTransport(const char* remoteHost, const char* proto = "udp") static void logTransports() static void getAllHostports(vector& vec) static void getAllLocalHostports(vector& vec) static void getAllExternalIps(vector& vec) static void getAllExternalContacts(vector>& vec) ``` -------------------------------- ### Get Endpoint Address and Port Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/client-server-protocol.md Retrieves the remote host address and port for outbound connections. Essential for understanding the destination of outgoing communication. ```cpp const string& endpoint_address() const ``` ```cpp unsigned short endpoint_port() const ``` -------------------------------- ### Enable Prometheus via Environment Variable Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/metrics-and-monitoring.md Enable Prometheus metrics scraping by setting the DRACHTIO_PROMETHEUS_SCRAPE_PORT environment variable. ```bash DRACHTIO_PROMETHEUS_SCRAPE_PORT=8088 ``` -------------------------------- ### Increment Counter with Labels Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/metrics-and-monitoring.md Increment a counter metric with associated labels to categorize the metric. This example shows incrementing 'drachtio_sip_requests_in_total' with 'direction' and 'protocol' labels. ```cpp typedef const std::map mapLabels_t; std::map labels; labels["direction"] = "inbound"; labels["protocol"] = "udp"; STATS_COUNTER_INCREMENT("drachtio_sip_requests_in_total", labels); ``` -------------------------------- ### SipDialog State Query Methods Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/classes-and-types.md Provides methods to query the state and details of a SIP dialog. ```cpp const std::string& getCallId() const const Endpoint_t& getLocalEndpoint() const const Endpoint_t& getRemoteEndpoint() const unsigned int getSipStatus() const time_t getStartTime() time_t getConnectTime() time_t getEndTime() bool isInviteDialog() const std::string& dialogId() const const std::string& getTransactionId() const DialogType_t getRole() const ``` -------------------------------- ### Configure TCP/TLS Admin Ports and Secret via Environment Variables Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/configuration.md Set environment variables to configure the TCP and TLS ports for admin client connections, and the admin bind address. ```bash DRACHTIO_ADMIN_TCP_PORT=9022 DRACHTIO_ADMIN_TLS_PORT=9023 DRACHTIO_ADMIN_SECRET=cymru DRACHTIO_ADMIN_ADDRESS=127.0.0.1 ``` -------------------------------- ### Set and Get Local Contact Header Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/dialog-management.md Manages the local Contact header for SIP dialogs. Use setLocalContactHeader to set the header and getLocalContactHeader to retrieve it. ```cpp void setLocalContactHeader(const char* szContact) ``` ```cpp const std::string& getLocalContactHeader() ``` -------------------------------- ### SipDialog Constructor for Outgoing INVITE Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/dialog-management.md Constructs a SipDialog for an outgoing INVITE request, acting as the UAC (User Agent Client). Requires transaction ID and transport information. ```cpp SipDialog(const std::string& transactionId, nta_leg_t* leg, nta_outgoing_t* orq, sip_t const *sip, msg_t *msg, const std::string& transport) ``` -------------------------------- ### Configure Drachtio Server Build with tcmalloc Source: https://github.com/drachtio/drachtio-server/blob/main/README.md Configures the build process to enable tcmalloc for enhanced memory management. Assumes autotools have been run and the build directory created. ```bash ../configure --enable-tcmalloc=yes CPPFLAGS='-DNDEBUG' ``` -------------------------------- ### SipTransport URI and Description Methods Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/classes-and-types.md Methods to obtain URI representations and descriptions of the SipTransport. ```cpp void getContactUri(string& contact, bool useExternalIp = true) void getBindableContactUri(string& contact) void getDescription(string& s, bool shortVersion = true) void getHostport(string& s) void getLocalHostport(string& s) ``` -------------------------------- ### Message Splitting Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/api-reference.md Splits a raw SIP message, including any associated metadata, into its core components: start line, headers, and body. The metadata is also extracted. ```APIDOC ## Message Splitting ### Description Splits a raw SIP message, including any associated metadata, into its core components: start line, headers, and body. The metadata is also extracted. ### Signature ```cpp void splitMsg(const string& msg, string& meta, string& startLine, string& headers, string& body) ``` ### Parameters #### Input Parameters - **msg** (const string&) - Raw SIP message with metadata #### Output Parameters - **meta** (string&) - Metadata (source, protocol, etc.) - **startLine** (string&) - SIP start line (request or response) - **headers** (string&) - SIP headers - **body** (string&) - Message body ``` -------------------------------- ### Client Class Template Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/client-server-protocol.md Defines the base class for client connections, with specializations for plain TCP and TLS sockets. ```cpp template class Client : public BaseClient { ``` -------------------------------- ### Split SIP Message Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/api-reference.md Splits a raw SIP message into its metadata, start line, headers, and body components. The output is stored in the provided string references. ```cpp void splitMsg(const string& msg, string& meta, string& startLine, string& headers, string& body) ``` -------------------------------- ### SipTransport Configuration Methods Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/classes-and-types.md Methods to configure SipTransport settings like DNS names, local network, netmask, and range. ```cpp void addDnsName(const string& name) void setLocalNet(const string& network, const string& bits) void setNetwork(const string& network) void setNetmask(uint32_t netmask) void setRange(uint32_t range) ``` -------------------------------- ### Get SIP Header Tag Type Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/api-reference.md Maps a SIP header name to its corresponding Sofia SIP tag constant. This is useful for manipulating message headers. ```cpp bool getTagTypeForHdr(const std::string& hdr, tag_type_t& tag) ``` -------------------------------- ### Get Transport Queue Size Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/advanced-features.md Retrieves the configured size of the transport queue for buffering messages. This impacts how many messages can be held during high load before being dropped. ```cpp unsigned int getTportQueuesize() ``` -------------------------------- ### Get UDP Buffer Size Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/advanced-features.md Retrieves the size of the UDP receive buffer. A larger buffer can help in tolerating larger datagrams and reducing packet loss. ```cpp unsigned int getUdpBufferSize() ``` -------------------------------- ### Create Tar Archive for RPM Build Source: https://github.com/drachtio/drachtio-server/blob/main/el/README.md Creates a gzipped tar archive named 'drachtio.tar.gz' containing the drachtio-server directory. This archive is used as input for rpmbuild. ```bash cd .. && tar -czvf drachtio.tar.gz drachtio-server/ ``` -------------------------------- ### Configure Syslog Logging via Environment Variables Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/configuration.md Set environment variables to configure the address, port, and facility for syslog logging. ```bash DRACHTIO_SYSLOG_ADDRESS=my.syslog.server DRACHTIO_SYSLOG_PORT=514 DRACHTIO_SYSLOG_FACILITY=local6 ``` -------------------------------- ### Enable Prometheus in C++ Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/metrics-and-monitoring.md Enable Prometheus metrics collection programmatically using the enablePrometheus function from the StatsCollector interface. ```cpp statsCollector.enablePrometheus("127.0.0.1:8088"); ``` -------------------------------- ### Get Maximum Transmission Unit (MTU) Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/advanced-features.md Retrieves the configured Maximum Transmission Unit (MTU) for network packets. This impacts how large SIP messages are handled, especially over UDP. ```cpp unsigned int getMtu() ``` -------------------------------- ### Get Preserved Header Names Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/advanced-features.md Retrieves the set of header names that are always preserved across proxy operations according to SIP RFC standards. These headers are not modified during proxying. ```cpp std::unordered_set& getPreservedHeaderNames() ``` -------------------------------- ### SDP Handling Getters and Setters Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/dialog-management.md Methods to check for the presence of local or remote SDP, and to set SDP content, either as a string or raw data with length. ```cpp bool hasLocalSdp() const bool hasRemoteSdp() const void setLocalSdp(const char* sdp) void setLocalSdp(const char* data, unsigned int len) void setRemoteSdp(const char* sdp) void setRemoteSdp(const char* data, unsigned int len) ``` -------------------------------- ### Run INFO during IIP Scenario Source: https://github.com/drachtio/drachtio-server/blob/main/test/leak-repro/README.md Executes the leak-tester with the --info-during-iip flag to reproduce a specific crash scenario involving an INFO request before the INVITE is answered. It runs for 50 iterations. ```bash ./leak-tester --drachtio host:port --transport udp --callee 15083084809 \ --info-during-iip --loop 50 ``` -------------------------------- ### Get Source Address for SIP Message Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/advanced-features.md Extracts the actual source IP address for a given SIP message, considering various scenarios like NAT and different header fields. ```cpp void getSourceAddressForMsg(msg_t *msg, string& host) ``` -------------------------------- ### Enable tcmalloc for Faster Allocation Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/advanced-features.md Configures the build to use tcmalloc for potentially faster memory allocation. This is a build-time option. ```bash ./configure --enable-tcmalloc=yes ``` -------------------------------- ### CDR Record Types Enum Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/metrics-and-monitoring.md Defines an enumeration for different types of Call Detail Records (CDRs): attempt, start, and stop. Each type represents a distinct phase of a call's lifecycle. ```cpp enum RecordType_t { attempt_record = 0, // Initial request start_record, // 200 OK stop_record // BYE/termination }; enum AgentRole_t { role_undefined = 0, proxy_uac, // Proxy acting as client proxy_uas, // Proxy acting as server uac, // Application acting as client uas // Application acting as server }; enum TerminationReason_t { no_termination = 0, call_rejected, call_canceled, normal_release, session_expired, ackbye, system_initiated_termination, system_error_initiated_termination }; ``` -------------------------------- ### Configure Prometheus Metrics Endpoint via Command-line Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/configuration.md Set the port for Prometheus metrics exposition using command-line arguments. You can specify just the port or the address and port. ```bash drachtio --prometheus-scrape-port 8088 ddrachtio --prometheus-scrape-port "0.0.0.0:8088" ``` -------------------------------- ### Configure Prometheus Metrics Source: https://github.com/drachtio/drachtio-server/blob/main/README.md Enable Drachtio to report metrics to Prometheus. Specify the scrape port and address. Configuration can be done via XML, command line, or environment variables. ```xml 172.28.0.23 ``` ```bash drachtio --prometheus-scrape-port 9090 ``` ```bash drachtio --prometheus-scrape-port "0.0.0.0:9090" ``` ```bash DRACHTIO_PROMETHEUS_SCRAPE_PORT=9090 drachtio ``` -------------------------------- ### Run Leak Reproducer with TCP Source: https://github.com/drachtio/drachtio-server/blob/main/test/leak-repro/README.md Executes the leak-tester using TCP transport on the default port 5060. This is the default configuration for testing. ```bash ./leak-tester --drachtio 127.0.0.1:5060 --callee 15083084809 ``` -------------------------------- ### Configure Logging Levels Source: https://github.com/drachtio/drachtio-server/blob/main/README.md Set log levels for Drachtio and the Sofia SIP stack. Supports console, file, or syslog output. Configuration can be done via XML, command line, or environment variables. ```xml 3 info ``` ```bash drachtio --loglevel info --sofia-loglevel 3 ``` ```bash DRACHTIO_LOGLEVEL=info DRACHTIO_SOFIA_LOGLEVEL=3 drachtio ``` -------------------------------- ### Set Minimum TLS Version via Environment Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/advanced-features.md Configures the minimum supported TLS version using the DRACHTIO_MIN_TLS_VERSION environment variable. ```bash DRACHTIO_MIN_TLS_VERSION=1.2 ``` -------------------------------- ### Configure Console Logging Level via Environment Variable Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/configuration.md Set the global log level for the Drachtio server using an environment variable. ```bash DRACHTIO_LOGLEVEL=info ``` -------------------------------- ### Homer SIP Capture Configuration (Command-line) Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/metrics-and-monitoring.md Configure Homer SIP capture server details using command-line arguments. This sets the target server address, port, and ID. ```bash drachtio --homer 172.28.0.23 --homer-id 101 --homer-port 9060 ``` -------------------------------- ### Configure Syslog Logging Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/configuration.md Configure Drachtio to send logs to a remote syslog server. Specify the server address, port, and facility. ```xml
my.syslog.server
514 local6
``` -------------------------------- ### Configure File Logging Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/configuration.md Configure Drachtio to log to a file, specifying the log file name, archive directory, and rotation parameters. This is suitable for persistent logging. ```xml /var/log/drachtio/drachtio.log /var/log/drachtio/archive 100 20 10 true ``` -------------------------------- ### TimerQueue Constructor Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/advanced-features.md Constructor for TimerQueue, integrating with a Sofia event root and optionally accepting a name. ```cpp TimerQueue(su_root_t* root, const char* szName = NULL) ``` -------------------------------- ### Configure Console Logging Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/configuration.md Enable console logging for the Drachtio server. This is a simple way to view logs during development or for basic monitoring. ```xml ``` -------------------------------- ### Manage INVITE Incoming Request (IRQ) Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/dialog-management.md Stores and retrieves the original incoming INVITE request to validate later retransmissions. Use setInviteIrq to store and getInviteIrq to retrieve. ```cpp void setInviteIrq(nta_incoming_t* irq) ``` ```cpp nta_incoming_t* getInviteIrq() const ``` ```cpp void clearInviteIrq() ``` -------------------------------- ### Configure IP Blacklisting Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/metrics-and-monitoring.md Enables IP blacklisting by specifying a Redis address and key for storing blocked IPs. ```bash drachtio --redis-address redis.example.com:6379 --redis-key blocked-ips ``` -------------------------------- ### Run Leak Reproducer with WSS Source: https://github.com/drachtio/drachtio-server/blob/main/test/leak-repro/README.md Executes the leak-tester using WebSocket Secure (WSS) transport. By default, it skips TLS certificate verification. ```bash ./leak-tester --drachtio host:port --transport wss --callee 15083084809 ``` -------------------------------- ### Configure TCP/TLS Admin Ports and Secret Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/configuration.md Set the TCP and TLS ports for admin client connections, along with a shared secret for authentication. This can be configured using XML, command-line arguments, or environment variables. ```xml 127.0.0.1 ``` -------------------------------- ### Configure Admin Port Source: https://github.com/drachtio/drachtio-server/blob/main/README.md Set the address and port for the admin interface, supporting TCP and TLS. Configuration can be done via XML, command line, or environment variables. ```xml 127.0.0.1 ``` ```bash drachtio --port 9022 --tls-port 9023 # address defaults to 0.0.0.0 ``` ```bash DRACHTIO_ADMIN_TCP_PORT=9022 DRACHTIO_ADMIN_TLS_PORT=9023 drachtio ``` -------------------------------- ### Configure Redis Blacklist Settings Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/advanced-features.md Configures the Drachtio server to use Redis for IP blacklisting, specifying connection details and refresh rate. ```bash drachtio --redis-address redis.example.com:6379 \ --redis-password secret \ --redis-key blocked-ips \ --redis-refresh 3600 ``` -------------------------------- ### Log Current Stats Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/metrics-and-monitoring.md Dumps all current metrics to logs. Include detailed Sofia stack stats by setting bDetail to true. ```cpp void printStats(bool bDetail) ``` -------------------------------- ### HTTP Response Action: Redirect Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/configuration.md Configure an action to redirect an incoming request to a new set of SIP contacts. ```json { "action": "redirect", "data": { "contacts": ["sip:user@destination.com"] } } ``` -------------------------------- ### Homer SIP Capture Configuration (Environment) Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/metrics-and-monitoring.md Configure Homer SIP capture server details using environment variables. This is an alternative method to command-line or config file settings. ```bash DRACHTIO_HOMER_ADDRESS=172.28.0.23 DRACHTIO_HOMER_PORT=9060 DRACHTIO_HOMER_ID=101 ``` -------------------------------- ### Syslog Logging Configuration Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/metrics-and-monitoring.md Configure syslog logging by specifying the syslog server address, port, and facility. This XML snippet details the necessary parameters. ```xml
syslog.example.com
514 local6
``` -------------------------------- ### File Logging Configuration Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/metrics-and-monitoring.md Configure file logging with options for log file path, archive directory, size limits, and rotation. This XML snippet defines these parameters. ```xml /var/log/drachtio/drachtio.log /var/log/drachtio/archive 100 20 true ``` -------------------------------- ### Configure Log Levels for Drachtio and Sofia Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/configuration.md Set the log level for the Drachtio server and the underlying Sofia-SIP stack. Use XML or command-line arguments. ```xml info 3 ``` -------------------------------- ### Route to Application by Tag Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/proxying-and-routing.md Instructs drachtio to route an incoming request to an application instance identified by a specific tag. This is useful for directing traffic to a particular application instance. ```json { "action": "route", "data": { "tag": "my-app-instance-1" } } ``` -------------------------------- ### Drachtio Server File Organization Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/README.md This snippet shows the directory structure of the Drachtio server source code, highlighting the purpose of key files and directories. ```tree src/ ├── main.cpp # Entry point ├── drachtio.h # Main include ├── drachtio.cpp # Core implementation ├── controller.hpp/cpp # Main controller ├── client.hpp/cpp # Client connections ├── client-controller.hpp/cpp # Client manager ├── sip-dialog.hpp/cpp # Dialog state ├── sip-dialog-controller.hpp/cpp # Dialog manager ├── sip-proxy-controller.hpp/cpp # Proxy implementation ├── request-handler.hpp/cpp # HTTP routing ├── sip-transports.hpp/cpp # Transport management ├── drachtio-config.hpp/cpp # Configuration parsing ├── stats-collector.hpp/cpp # Metrics ├── cdr.hpp/cpp # Call detail records ├── blacklist.hpp/cpp # IP blacklisting ├── timer-queue.hpp/cpp # Timer scheduling ├── timer-queue-manager.hpp/cpp # Multi-queue management ├── invite-in-progress.hpp/cpp # INVITE state tracking ├── pending-request-controller.hpp/cpp # Pending request tracking └── test/ # Unit tests ``` -------------------------------- ### BaseClient Message Handling Methods Source: https://github.com/drachtio/drachtio-server/blob/main/_autodocs/classes-and-types.md Methods for processing incoming client messages and sending various types of messages to clients. ```cpp bool processClientMessage(const string& msg, string& msgResponse) void sendSipMessageToClient(const string& transactionId, const string& dialogId, const string& rawSipMsg, const SipMsgData_t& meta) void sendSipMessageToClient(const string& transactionId, const string& rawSipMsg, const SipMsgData_t& meta) void sendCdrToClient(const string& rawSipMsg, const string& meta) void sendApiResponseToClient(const string& clientMsgId, const string& responseText, const string& additionalResponseText) ```