Navigation


Changeset 1396:188c82b6690b in freeDiameter for libfdcore/p_ce.c


Ignore:
Timestamp:
Nov 15, 2019, 7:38:30 PM (4 years ago)
Author:
Thomas Klausner <tk@giga.or.at>
Branch:
default
Phase:
public
Message:

Add ProcessingPeersPattern? and ProcessingPeersMinimum? parameters.

If this is configured, the process will accept all connections from
peers matching ProcessingPeersPattern?, but will NOT accept connections
from other peers until ProcessingPeersMinimum? peers of the first
type are connected.

This allows relays to only go online if there are enough worker
peers connected behind them.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libfdcore/p_ce.c

    r1281 r1396  
    834834}
    835835
     836/* Check if enough processing peers are connected to allow connections by other peers */
     837static int sufficient_processing_peers(void) {
     838        int processing_peers_count = 0;
     839        struct fd_list * li;
     840
     841        CHECK_FCT( pthread_rwlock_rdlock(&fd_g_activ_peers_rw) );
     842        for (li = fd_g_activ_peers.next; li != &fd_g_activ_peers; li = li->next) {
     843                struct fd_peer * p = (struct fd_peer *)li->o;
     844
     845                TRACE_DEBUG(FULL, "comparing '%s' against processing peers pattern", p->p_hdr.info.pi_diamid);
     846                if (regexec(&fd_g_config->cnf_processing_peers_pattern_regex, p->p_hdr.info.pi_diamid, 0, NULL, 0) == 0) {
     847                        processing_peers_count++;
     848                }
     849        }
     850        CHECK_FCT( pthread_rwlock_unlock(&fd_g_activ_peers_rw) );
     851
     852        TRACE_DEBUG(FULL, "%d processing peers found", processing_peers_count);
     853        return (processing_peers_count >= fd_g_config->cnf_processing_peers_minimum);
     854}
     855
    836856/* Handle the receiver side to go to OPEN or OPEN_NEW state (any election is resolved) */
    837857int fd_p_ce_process_receiver(struct fd_peer * peer)
     
    884904        }
    885905       
     906        /* Check peer type and if enough processing peers are already connected */
     907        if (fd_g_config->cnf_processing_peers_minimum > 0) {
     908                if (regexec(&fd_g_config->cnf_processing_peers_pattern_regex, peer->p_hdr.info.pi_diamid, 0, NULL, 0) != 0) {
     909                        /* peer is not a processing peer */
     910                        if (!sufficient_processing_peers()) {
     911                                pei.pei_errcode = "DIAMETER_TOO_BUSY";
     912                                goto error_abort;
     913                        }
     914                }
     915        }
     916
     917        if (peer->p_flags.pf_responder) {
     918                int res = fd_peer_validate( peer );
     919                if (res < 0) {
     920                        TRACE_DEBUG(INFO, "Rejected CER from peer '%s', validation failed (returning DIAMETER_UNKNOWN_PEER).", peer->p_hdr.info.pi_diamid);
     921                        pei.pei_errcode = "DIAMETER_UNKNOWN_PEER";
     922                        goto error_abort;
     923                }
     924                CHECK_FCT( res );
     925        }
    886926        /* Check if we have common applications */
    887927        if ( fd_g_config->cnf_flags.no_fwd && (! peer->p_hdr.info.runtime.pir_relay) ) {
Note: See TracChangeset for help on using the changeset viewer.