X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=trp%2Ftrp_ptable.c;h=7552cff7bc9c09d2f4285458ab1b1cee95246eed;hb=1a3ad555c6b58de28efb85e7ab07c2f35208ab0d;hp=53963e80a0076ca1052576d246226f8083dfafd3;hpb=f52f20507c568db42dbd2ddc99c7fa5a27012868;p=trust_router.git diff --git a/trp/trp_ptable.c b/trp/trp_ptable.c index 53963e8..7552cff 100644 --- a/trp/trp_ptable.c +++ b/trp/trp_ptable.c @@ -1,15 +1,51 @@ +/* + * Copyright (c) 2016, JANET(UK) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of JANET(UK) nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + #include #include -#include +#include #include -#include +#include #include #include static int trp_peer_destructor(void *object) { TRP_PEER *peer=talloc_get_type_abort(object, TRP_PEER); + if (peer->label!=NULL) + tr_free_name(peer->label); if (peer->servicename!=NULL) tr_free_name(peer->servicename); return 0; @@ -19,6 +55,7 @@ TRP_PEER *trp_peer_new(TALLOC_CTX *memctx) TRP_PEER *peer=talloc(memctx, TRP_PEER); if (peer!=NULL) { peer->next=NULL; + peer->label=NULL; peer->server=NULL; peer->servicename=NULL; peer->gss_names=NULL; @@ -29,6 +66,7 @@ TRP_PEER *trp_peer_new(TALLOC_CTX *memctx) peer->incoming_status=PEER_DISCONNECTED; peer->conn_status_cb=NULL; peer->conn_status_cookie=NULL; + peer->filters=NULL; talloc_set_destructor((void *)peer, trp_peer_destructor); } return peer; @@ -52,15 +90,16 @@ static TRP_PEER *trp_peer_tail(TRP_PEER *peer) * Do not modify or free the label. */ TR_NAME *trp_peer_get_label(TRP_PEER *peer) { - TR_GSS_NAMES_ITER *iter=tr_gss_names_iter_new(NULL); - TR_NAME *name=NULL; + char *s=NULL; - /* for now, use the first gss name */ - if (iter!=NULL) { - name=tr_gss_names_iter_first(iter, peer->gss_names); - talloc_free(iter); + if (peer->label==NULL) { + s=talloc_asprintf(NULL, "%s:%u", peer->server, peer->port); + if (s!=NULL) { + peer->label=tr_new_name(s); + talloc_free(s); + } } - return name; + return peer->label; } /* Get a name that identifies this peer for display to the user, etc. @@ -109,7 +148,7 @@ void trp_peer_add_gss_name(TRP_PEER *peer, TR_NAME *gss_name) void trp_peer_set_gss_names(TRP_PEER *peer, TR_GSS_NAMES *gss_names) { if (peer->gss_names!=NULL) - talloc_free(peer->gss_names); + tr_gss_names_free(peer->gss_names); peer->gss_names=gss_names; talloc_steal(peer, gss_names); @@ -168,6 +207,27 @@ void trp_peer_set_conn_status_cb(TRP_PEER *peer, void (*cb)(TRP_PEER *, void *), peer->conn_status_cookie=cookie; } +/** + * Set the filter associated with this peer. Any existing filter will be freed. Takes responsibility for + * freeing the new filter. + * + * @param peer Peer to modify + * @param filts New filter to attach to the peer + */ +void trp_peer_set_filters(TRP_PEER *peer, TR_FILTER_SET *filts) +{ + if (peer->filters!=NULL) + tr_filter_set_free(peer->filters); + + peer->filters=filts; + talloc_steal(peer, filts); +} + +TR_FILTER *trp_peer_get_filter(TRP_PEER *peer, TR_FILTER_TYPE ftype) +{ + return tr_filter_set_get(peer->filters, ftype); +} + struct timespec *trp_peer_get_last_conn_attempt(TRP_PEER *peer) { return &(peer->last_conn_attempt);