Ignore:
Timestamp:
Jan 24, 2013, 11:59:52 PM (9 years ago)
Author:
jordan
Message:

(libT) copyediting: modify more files to the new indentation/whitespace formatting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/port-forwarding.c

    r13631 r13863  
    3333struct tr_shared
    3434{
    35     bool              isEnabled;
    36     bool              isShuttingDown;
    37     bool              doPortCheck;
    38 
    39     tr_port_forwarding    natpmpStatus;
    40     tr_port_forwarding    upnpStatus;
    41 
    42     tr_upnp            * upnp;
    43     tr_natpmp          * natpmp;
    44     tr_session          * session;
    45 
    46     struct event        * timer;
     35  bool isEnabled;
     36  bool isShuttingDown;
     37  bool doPortCheck;
     38
     39  tr_port_forwarding natpmpStatus;
     40  tr_port_forwarding upnpStatus;
     41
     42  tr_upnp * upnp;
     43  tr_natpmp * natpmp;
     44  tr_session * session;
     45
     46  struct event * timer;
    4747};
    4848
     
    5454getNatStateStr (int state)
    5555{
    56     switch (state)
    57     {
    58         case TR_PORT_MAPPING:   return _("Starting");
    59         case TR_PORT_MAPPED:    return _("Forwarded");
    60         case TR_PORT_UNMAPPING: return _("Stopping");
    61         case TR_PORT_UNMAPPED:  return _("Not forwarded");
    62         default:                return "???";
     56  switch (state)
     57    {
     58      case TR_PORT_MAPPING:   return _("Starting");
     59      case TR_PORT_MAPPED:    return _("Forwarded");
     60      case TR_PORT_UNMAPPING: return _("Stopping");
     61      case TR_PORT_UNMAPPED:  return _("Not forwarded");
     62      default:                return "???";
    6363    }
    6464}
     
    6767natPulse (tr_shared * s, bool do_check)
    6868{
    69     const tr_port private_peer_port = s->session->private_peer_port;
    70     const int is_enabled = s->isEnabled && !s->isShuttingDown;
    71     tr_port public_peer_port;
    72     int oldStatus;
    73     int newStatus;
    74 
    75     if (s->natpmp == NULL)
    76         s->natpmp = tr_natpmpInit ();
    77     if (s->upnp == NULL)
    78         s->upnp = tr_upnpInit ();
    79 
    80     oldStatus = tr_sharedTraversalStatus (s);
    81 
    82     s->natpmpStatus = tr_natpmpPulse (s->natpmp, private_peer_port, is_enabled, &public_peer_port);
    83     if (s->natpmpStatus == TR_PORT_MAPPED)
    84         s->session->public_peer_port = public_peer_port;
    85 
    86     s->upnpStatus = tr_upnpPulse (s->upnp, private_peer_port, is_enabled, do_check);
    87 
    88     newStatus = tr_sharedTraversalStatus (s);
    89 
    90     if (newStatus != oldStatus)
    91         tr_ninf (getKey (), _("State changed from \"%1$s\" to \"%2$s\""),
    92                 getNatStateStr (oldStatus),
    93                 getNatStateStr (newStatus));
     69  int oldStatus;
     70  int newStatus;
     71  tr_port public_peer_port;
     72  const tr_port private_peer_port = s->session->private_peer_port;
     73  const int is_enabled = s->isEnabled && !s->isShuttingDown;
     74
     75  if (s->natpmp == NULL)
     76    s->natpmp = tr_natpmpInit ();
     77
     78  if (s->upnp == NULL)
     79    s->upnp = tr_upnpInit ();
     80
     81  oldStatus = tr_sharedTraversalStatus (s);
     82
     83  s->natpmpStatus = tr_natpmpPulse (s->natpmp, private_peer_port, is_enabled, &public_peer_port);
     84  if (s->natpmpStatus == TR_PORT_MAPPED)
     85    s->session->public_peer_port = public_peer_port;
     86
     87  s->upnpStatus = tr_upnpPulse (s->upnp, private_peer_port, is_enabled, do_check);
     88
     89  newStatus = tr_sharedTraversalStatus (s);
     90
     91  if (newStatus != oldStatus)
     92    tr_ninf (getKey (), _("State changed from \"%1$s\" to \"%2$s\""),
     93             getNatStateStr (oldStatus),
     94             getNatStateStr (newStatus));
    9495}
    9596
     
    9798set_evtimer_from_status (tr_shared * s)
    9899{
    99     int sec=0, msec=0;
    100 
    101     /* when to wake up again */
    102     switch (tr_sharedTraversalStatus (s))
    103     {
    104         case TR_PORT_MAPPED:
    105             /* if we're mapped, everything is fine... check back in 20 minutes
    106              * to renew the port forwarding if it's expired */
    107             s->doPortCheck = true;
    108             sec = 60 * 20;
    109             break;
    110 
    111         case TR_PORT_ERROR:
    112             /* some kind of an error. wait 60 seconds and retry */
    113             sec = 60;
    114             break;
    115 
    116         default:
    117             /* in progress. pulse frequently. */
    118             msec = 333000;
    119             break;
    120     }
    121 
    122     if (s->timer != NULL)
    123         tr_timerAdd (s->timer, sec, msec);
     100  int sec=0, msec=0;
     101
     102  /* when to wake up again */
     103  switch (tr_sharedTraversalStatus (s))
     104    {
     105      case TR_PORT_MAPPED:
     106        /* if we're mapped, everything is fine... check back in 20 minutes
     107         * to renew the port forwarding if it's expired */
     108        s->doPortCheck = true;
     109        sec = 60 * 20;
     110        break;
     111
     112      case TR_PORT_ERROR:
     113        /* some kind of an error. wait 60 seconds and retry */
     114        sec = 60;
     115        break;
     116
     117      default:
     118        /* in progress. pulse frequently. */
     119        msec = 333000;
     120        break;
     121    }
     122
     123  if (s->timer != NULL)
     124    tr_timerAdd (s->timer, sec, msec);
    124125}
    125126
     
    127128onTimer (int fd UNUSED, short what UNUSED, void * vshared)
    128129{
    129     tr_shared * s = vshared;
    130 
    131     assert (s);
    132     assert (s->timer);
    133 
    134     /* do something */
    135     natPulse (s, s->doPortCheck);
    136     s->doPortCheck = false;
    137 
    138     /* set up the timer for the next pulse */
    139     set_evtimer_from_status (s);
     130  tr_shared * s = vshared;
     131
     132  assert (s);
     133  assert (s->timer);
     134
     135  /* do something */
     136  natPulse (s, s->doPortCheck);
     137  s->doPortCheck = false;
     138
     139  /* set up the timer for the next pulse */
     140  set_evtimer_from_status (s);
    140141}
    141142
     
    147148tr_sharedInit (tr_session  * session)
    148149{
    149     tr_shared * s = tr_new0 (tr_shared, 1);
    150 
    151     s->session      = session;
    152     s->isEnabled    = false;
    153     s->upnpStatus  = TR_PORT_UNMAPPED;
    154     s->natpmpStatus = TR_PORT_UNMAPPED;
     150  tr_shared * s = tr_new0 (tr_shared, 1);
     151
     152  s->session = session;
     153  s->isEnabled = false;
     154  s->upnpStatus = TR_PORT_UNMAPPED;
     155  s->natpmpStatus = TR_PORT_UNMAPPED;
    155156
    156157#if 0
    157     if (isEnabled)
    158     {
    159         s->timer = tr_new0 (struct event, 1);
    160         evtimer_set (s->timer, onTimer, s);
    161         tr_timerAdd (s->timer, 0, 333000);
     158  if (isEnabled)
     159    {
     160      s->timer = tr_new0 (struct event, 1);
     161      evtimer_set (s->timer, onTimer, s);
     162      tr_timerAdd (s->timer, 0, 333000);
    162163    }
    163164#endif
    164165
    165     return s;
     166  return s;
    166167}
    167168
     
    169170stop_timer (tr_shared * s)
    170171{
    171     if (s->timer != NULL)
    172     {
    173         event_free (s->timer);
    174         s->timer = NULL;
     172  if (s->timer != NULL)
     173    {
     174      event_free (s->timer);
     175      s->timer = NULL;
    175176    }
    176177}
     
    179180stop_forwarding (tr_shared * s)
    180181{
    181     tr_ninf (getKey (), "%s", _("Stopped"));
    182     natPulse (s, false);
    183 
    184     tr_natpmpClose (s->natpmp);
    185     s->natpmp = NULL;
    186     s->natpmpStatus = TR_PORT_UNMAPPED;
    187 
    188     tr_upnpClose (s->upnp);
    189     s->upnp = NULL;
    190     s->upnpStatus = TR_PORT_UNMAPPED;
    191 
    192     stop_timer (s);
     182  tr_ninf (getKey (), "%s", _("Stopped"));
     183  natPulse (s, false);
     184
     185  tr_natpmpClose (s->natpmp);
     186  s->natpmp = NULL;
     187  s->natpmpStatus = TR_PORT_UNMAPPED;
     188
     189  tr_upnpClose (s->upnp);
     190  s->upnp = NULL;
     191  s->upnpStatus = TR_PORT_UNMAPPED;
     192
     193  stop_timer (s);
    193194}
    194195
     
    196197tr_sharedClose (tr_session * session)
    197198{
    198     tr_shared * s = session->shared;
    199 
    200     s->isShuttingDown = true;
    201     stop_forwarding (s);
    202     s->session->shared = NULL;
    203     tr_free (s);
     199  tr_shared * s = session->shared;
     200
     201  s->isShuttingDown = true;
     202  stop_forwarding (s);
     203  s->session->shared = NULL;
     204  tr_free (s);
    204205}
    205206
     
    207208start_timer (tr_shared * s)
    208209{
    209     s->timer = evtimer_new (s->session->event_base, onTimer, s);
    210     set_evtimer_from_status (s);
     210  s->timer = evtimer_new (s->session->event_base, onTimer, s);
     211  set_evtimer_from_status (s);
    211212}
    212213
     
    214215tr_sharedTraversalEnable (tr_shared * s, bool isEnabled)
    215216{
    216     if ((s->isEnabled = isEnabled))
    217         start_timer (s);
    218     else
    219         stop_forwarding (s);
     217  if ((s->isEnabled = isEnabled))
     218    start_timer (s);
     219  else
     220    stop_forwarding (s);
    220221}
    221222
     
    223224tr_sharedPortChanged (tr_session * session)
    224225{
    225     tr_shared * s = session->shared;
    226 
    227     if (s->isEnabled)
    228     {
    229         stop_timer (s);
    230         natPulse (s, false);
    231         start_timer (s);
     226  tr_shared * s = session->shared;
     227
     228  if (s->isEnabled)
     229    {
     230      stop_timer (s);
     231      natPulse (s, false);
     232      start_timer (s);
    232233    }
    233234}
     
    236237tr_sharedTraversalIsEnabled (const tr_shared * s)
    237238{
    238     return s->isEnabled;
     239  return s->isEnabled;
    239240}
    240241
     
    242243tr_sharedTraversalStatus (const tr_shared * s)
    243244{
    244     return MAX (s->natpmpStatus, s->upnpStatus);
    245 }
     245  return MAX (s->natpmpStatus, s->upnpStatus);
     246}
Note: See TracChangeset for help on using the changeset viewer.