comparison libfdcore/p_ce.c @ 1396:188c82b6690b

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.
author Thomas Klausner <tk@giga.or.at>
date Fri, 15 Nov 2019 11:38:30 +0100
parents ab6457399be2
children 3cbe458fbfa9
comparison
equal deleted inserted replaced
1395:603a72c4bf6c 1396:188c82b6690b
831 CHECK_FCT( fd_event_send(peer->p_events, FDEVP_CNX_ERROR, 0, NULL) ); 831 CHECK_FCT( fd_event_send(peer->p_events, FDEVP_CNX_ERROR, 0, NULL) );
832 832
833 return 0; 833 return 0;
834 } 834 }
835 835
836 /* Check if enough processing peers are connected to allow connections by other peers */
837 static 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
836 /* Handle the receiver side to go to OPEN or OPEN_NEW state (any election is resolved) */ 856 /* Handle the receiver side to go to OPEN or OPEN_NEW state (any election is resolved) */
837 int fd_p_ce_process_receiver(struct fd_peer * peer) 857 int fd_p_ce_process_receiver(struct fd_peer * peer)
838 { 858 {
839 struct fd_pei pei; 859 struct fd_pei pei;
840 struct msg * msg = NULL; 860 struct msg * msg = NULL;
881 goto error_abort; 901 goto error_abort;
882 } 902 }
883 CHECK_FCT( res ); 903 CHECK_FCT( res );
884 } 904 }
885 905
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 }
886 /* Check if we have common applications */ 926 /* Check if we have common applications */
887 if ( fd_g_config->cnf_flags.no_fwd && (! peer->p_hdr.info.runtime.pir_relay) ) { 927 if ( fd_g_config->cnf_flags.no_fwd && (! peer->p_hdr.info.runtime.pir_relay) ) {
888 int got_common; 928 int got_common;
889 CHECK_FCT( fd_app_check_common( &fd_g_config->cnf_apps, &peer->p_hdr.info.runtime.pir_apps, &got_common) ); 929 CHECK_FCT( fd_app_check_common( &fd_g_config->cnf_apps, &peer->p_hdr.info.runtime.pir_apps, &got_common) );
890 if (!got_common) { 930 if (!got_common) {
"Welcome to our mercurial repository"