aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFabian Oehlmann <oehlmann@in.tum.de>2013-09-26 18:46:51 +0000
committerFabian Oehlmann <oehlmann@in.tum.de>2013-09-26 18:46:51 +0000
commitd79a03493ba5d0581e828724a402a2054429e7be (patch)
tree08e4bebcfb18e4997600e69f3219ee3ce0f35168 /src
parentdfd948d2cc5e313dd4cd34559c923241ac211572 (diff)
downloadgnunet-d79a03493ba5d0581e828724a402a2054429e7be.tar.gz
gnunet-d79a03493ba5d0581e828724a402a2054429e7be.zip
ats_ril: address administration changed
Diffstat (limited to 'src')
-rwxr-xr-xsrc/ats/gnunet-service-ats-solver_ril.c648
1 files changed, 337 insertions, 311 deletions
diff --git a/src/ats/gnunet-service-ats-solver_ril.c b/src/ats/gnunet-service-ats-solver_ril.c
index 9aecd1747..c80b85604 100755
--- a/src/ats/gnunet-service-ats-solver_ril.c
+++ b/src/ats/gnunet-service-ats-solver_ril.c
@@ -30,6 +30,8 @@
30#include "gnunet-service-ats_addresses.h" 30#include "gnunet-service-ats_addresses.h"
31#include "gnunet_statistics_service.h" 31#include "gnunet_statistics_service.h"
32 32
33#define LOG(kind,...) GNUNET_log_from (kind, "ats-ril",__VA_ARGS__)
34
33#define RIL_DEFAULT_STEP_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 3000) 35#define RIL_DEFAULT_STEP_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 3000)
34#define RIL_DEFAULT_ALGORITHM RIL_ALGO_Q 36#define RIL_DEFAULT_ALGORITHM RIL_ALGO_Q
35#define RIL_DEFAULT_DISCOUNT_FACTOR 0.5 37#define RIL_DEFAULT_DISCOUNT_FACTOR 0.5
@@ -43,6 +45,11 @@
43 * General description 45 * General description
44 */ 46 */
45 47
48/**
49 * TODO! implement address administration
50 * TODO! implement reward calculation 1 and 2 (i.e. meeting preferences and taking scores)
51 */
52
46enum RIL_Action_Type 53enum RIL_Action_Type
47{ 54{
48 RIL_ACTION_NOTHING = 0, 55 RIL_ACTION_NOTHING = 0,
@@ -60,12 +67,16 @@ enum RIL_Action_Type
60 67
61enum RIL_Algorithm 68enum RIL_Algorithm
62{ 69{
63 RIL_ALGO_SARSA = 0, RIL_ALGO_Q = 1 70 RIL_ALGO_SARSA = 0,
71 RIL_ALGO_Q = 1
64}; 72};
65 73
66enum RIL_E_Modification 74enum RIL_E_Modification
67{ 75{
68 RIL_E_SET, RIL_E_ZERO, RIL_E_ACCUMULATE, RIL_E_REPLACE 76 RIL_E_SET,
77 RIL_E_ZERO,
78 RIL_E_ACCUMULATE,
79 RIL_E_REPLACE
69}; 80};
70 81
71/** 82/**
@@ -94,6 +105,27 @@ struct RIL_Learning_Parameters
94 float lambda; 105 float lambda;
95}; 106};
96 107
108/**
109 * Wrapper for addresses to store them in agent's linked list
110 */
111struct RIL_Address_Wrapped
112{
113 /**
114 * Next in DLL
115 */
116 struct RIL_Address_Wrapped *next;
117
118 /**
119 * Previous in DLL
120 */
121 struct RIL_Address_Wrapped *prev;
122
123 /**
124 * The address
125 */
126 struct ATS_Address *address_naked;
127};
128
97struct RIL_Peer_Agent 129struct RIL_Peer_Agent
98{ 130{
99 /** 131 /**
@@ -134,12 +166,12 @@ struct RIL_Peer_Agent
134 /** 166 /**
135 * Number of rows of W / Number of state-vector features 167 * Number of rows of W / Number of state-vector features
136 */ 168 */
137 int m; 169 unsigned int m;
138 170
139 /** 171 /**
140 * Number of columns of W / Number of actions 172 * Number of columns of W / Number of actions
141 */ 173 */
142 int n; 174 unsigned int n;
143 175
144 /** 176 /**
145 * Last perceived state feature vector 177 * Last perceived state feature vector
@@ -159,7 +191,17 @@ struct RIL_Peer_Agent
159 /** 191 /**
160 * Address in use 192 * Address in use
161 */ 193 */
162 struct ATS_Address * address; 194 struct ATS_Address * address_inuse;
195
196 /**
197 * Head of addresses DLL
198 */
199 struct RIL_Address_Wrapped * addresses_head;
200
201 /**
202 * Tail of addresses DLL
203 */
204 struct RIL_Address_Wrapped * addresses_tail;
163 205
164 /** 206 /**
165 * Inbound bandwidth assigned by the agent 207 * Inbound bandwidth assigned by the agent
@@ -338,20 +380,55 @@ agent_decide_exploration (struct RIL_Peer_Agent *agent)
338 double r = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 380 double r = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
339 UINT32_MAX) / (double) UINT32_MAX; 381 UINT32_MAX) / (double) UINT32_MAX;
340 382
341 if (r < RIL_EXPLORE_RATIO) 383if (r < RIL_EXPLORE_RATIO)
342 { 384 {
343 return GNUNET_YES; 385 return GNUNET_YES;
344 } 386 }
345 return GNUNET_NO; 387 return GNUNET_NO;
346} 388}
347 389
348/** 390static int
349 * Gets the action, with the maximal estimated Q-value (i.e. the one currently estimated to bring the 391agent_address_get_index (struct RIL_Peer_Agent *agent, struct ATS_Address *address)
350 * most reward in the future) 392{
351 * @param agent agent performing the calculation 393 int i;
352 * @param state the state from which to take the action 394 struct RIL_Address_Wrapped *cur;
353 * @return the action promising most future reward 395
354 */ 396 i = 0;
397 for (cur = agent->addresses_head; NULL != cur; cur = cur->next)
398 {
399 if (cur->address_naked == address)
400 {
401 return i;
402 }
403 i++;
404 }
405
406 return -1;
407}
408
409static struct RIL_Address_Wrapped *
410agent_address_get (struct RIL_Peer_Agent *agent, struct ATS_Address *address)
411{
412 struct RIL_Address_Wrapped *cur;
413
414 for (cur = agent->addresses_head; NULL != cur; cur = cur->next)
415 {
416 if (cur->address_naked == address)
417 {
418 return cur;
419 }
420 }
421
422 return NULL;
423}
424
425 /**
426 * Gets the action, with the maximal estimated Q-value (i.e. the one currently estimated to bring the
427 * most reward in the future)
428 * @param agent agent performing the calculation
429 * @param state the state from which to take the action
430 * @return the action promising most future reward
431 */
355static int 432static int
356agent_get_action_best (struct RIL_Peer_Agent *agent, double *state) 433agent_get_action_best (struct RIL_Peer_Agent *agent, double *state)
357{ 434{
@@ -395,10 +472,7 @@ agent_get_action_explore (struct RIL_Peer_Agent *agent, double *state)
395 * @param a_prime the new 472 * @param a_prime the new
396 */ 473 */
397static void 474static void
398agent_update_weights (struct RIL_Peer_Agent *agent, 475agent_update_weights (struct RIL_Peer_Agent *agent, double reward, double *s_next, int a_prime)
399 double reward,
400 double *s_next,
401 int a_prime)
402{ 476{
403 int i; 477 int i;
404 double delta; 478 double delta;
@@ -422,8 +496,7 @@ agent_update_weights (struct RIL_Peer_Agent *agent,
422 * @param mod 496 * @param mod
423 */ 497 */
424static void 498static void
425agent_modify_eligibility (struct RIL_Peer_Agent *agent, 499agent_modify_eligibility (struct RIL_Peer_Agent *agent, enum RIL_E_Modification mod)
426 enum RIL_E_Modification mod)
427{ 500{
428 int i; 501 int i;
429 double *e = agent->e; 502 double *e = agent->e;
@@ -451,7 +524,7 @@ agent_modify_eligibility (struct RIL_Peer_Agent *agent,
451} 524}
452 525
453static void 526static void
454envi_change_active_address (struct GAS_RIL_Handle *solver, 527envi_set_active_suggestion (struct GAS_RIL_Handle *solver,
455 struct RIL_Peer_Agent *agent, 528 struct RIL_Peer_Agent *agent,
456 struct ATS_Address *new_address, 529 struct ATS_Address *new_address,
457 unsigned long long new_bw_in, 530 unsigned long long new_bw_in,
@@ -459,32 +532,34 @@ envi_change_active_address (struct GAS_RIL_Handle *solver,
459{ 532{
460 int notify = GNUNET_NO; 533 int notify = GNUNET_NO;
461 534
462 if (agent->address != new_address) 535 if (agent->address_inuse != new_address)
463 { 536 {
464 agent->address->active = GNUNET_NO; 537 if (NULL != agent->address_inuse)
465 agent->address = new_address; 538 {
466 agent->address->active = GNUNET_YES; 539 agent->address_inuse->active = GNUNET_NO;
467 agent->address->assigned_bw_in.value__ = htonl (agent->bw_in); 540 }
468 agent->address->assigned_bw_out.value__ = htonl (agent->bw_out); 541 agent->address_inuse = new_address;
542 agent->address_inuse->active = GNUNET_YES;
543 agent->address_inuse->assigned_bw_in.value__ = htonl (agent->bw_in);
544 agent->address_inuse->assigned_bw_out.value__ = htonl (agent->bw_out);
469 notify |= GNUNET_YES; 545 notify |= GNUNET_YES;
470 } 546 }
471 if (agent->bw_in != new_bw_in) 547 if (agent->bw_in != new_bw_in)
472 { 548 {
473 agent->bw_in = new_bw_in; 549 agent->bw_in = new_bw_in;
474 agent->address->assigned_bw_in.value__ = htonl (new_bw_out); 550 agent->address_inuse->assigned_bw_in.value__ = htonl (new_bw_out);
475 notify |= GNUNET_YES; 551 notify |= GNUNET_YES;
476 } 552 }
477 if (agent->bw_out != new_bw_out) 553 if (agent->bw_out != new_bw_out)
478 { 554 {
479 agent->bw_out = new_bw_out; 555 agent->bw_out = new_bw_out;
480 agent->address->assigned_bw_out.value__ = htonl (new_bw_out); 556 agent->address_inuse->assigned_bw_out.value__ = htonl (new_bw_out);
481 notify |= GNUNET_YES; 557 notify |= GNUNET_YES;
482 } 558 }
483 559
484 if (notify) 560 if (notify && agent->active)
485 { 561 {
486 solver->callbacks->bw_changed (solver->callbacks->bw_changed_cls, 562 solver->callbacks->bw_changed (solver->callbacks->bw_changed_cls, agent->address_inuse);
487 agent->address);
488 } 563 }
489} 564}
490 565
@@ -522,8 +597,8 @@ envi_get_reward (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
522{ 597{
523 //TODO! implement reward calculation 598 //TODO! implement reward calculation
524 599
525 return (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 600 return (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX)
526 UINT32_MAX) / (double) UINT32_MAX; 601 / (double) UINT32_MAX;
527} 602}
528 603
529static void 604static void
@@ -533,13 +608,11 @@ envi_action_bw_double (struct GAS_RIL_Handle *solver,
533{ 608{
534 if (direction_in) 609 if (direction_in)
535 { 610 {
536 envi_change_active_address (solver, agent, agent->address, agent->bw_in * 2, 611 envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in * 2, agent->bw_out);
537 agent->bw_out);
538 } 612 }
539 else 613 else
540 { 614 {
541 envi_change_active_address (solver, agent, agent->address, agent->bw_in, 615 envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in, agent->bw_out * 2);
542 agent->bw_out * 2);
543 } 616 }
544} 617}
545 618
@@ -556,42 +629,36 @@ envi_action_bw_halven (struct GAS_RIL_Handle *solver,
556 new_bw = agent->bw_in / 2; 629 new_bw = agent->bw_in / 2;
557 if (new_bw < min_bw) 630 if (new_bw < min_bw)
558 new_bw = min_bw; 631 new_bw = min_bw;
559 envi_change_active_address (solver, agent, agent->address, new_bw, 632 envi_set_active_suggestion (solver, agent, agent->address_inuse, new_bw, agent->bw_out);
560 agent->bw_out);
561 } 633 }
562 else 634 else
563 { 635 {
564 new_bw = agent->bw_out / 2; 636 new_bw = agent->bw_out / 2;
565 if (new_bw < min_bw) 637 if (new_bw < min_bw)
566 new_bw = min_bw; 638 new_bw = min_bw;
567 envi_change_active_address (solver, agent, agent->address, agent->bw_in, 639 envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in, new_bw);
568 new_bw);
569 } 640 }
570} 641}
571 642
572static void 643static void
573envi_action_bw_inc (struct GAS_RIL_Handle *solver, 644envi_action_bw_inc (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int direction_in)
574 struct RIL_Peer_Agent *agent,
575 int direction_in)
576{ 645{
577 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__); 646 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
578 647
579 if (direction_in) 648 if (direction_in)
580 { 649 {
581 envi_change_active_address (solver, agent, agent->address, 650 envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in + (5 * min_bw),
582 agent->bw_in + (5 * min_bw), agent->bw_out); 651 agent->bw_out);
583 } 652 }
584 else 653 else
585 { 654 {
586 envi_change_active_address (solver, agent, agent->address, agent->bw_in, 655 envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in,
587 agent->bw_out + (5 * min_bw)); 656 agent->bw_out + (5 * min_bw));
588 } 657 }
589} 658}
590 659
591static void 660static void
592envi_action_bw_dec (struct GAS_RIL_Handle *solver, 661envi_action_bw_dec (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int direction_in)
593 struct RIL_Peer_Agent *agent,
594 int direction_in)
595{ 662{
596 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__); 663 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
597 unsigned long long new_bw; 664 unsigned long long new_bw;
@@ -601,16 +668,14 @@ envi_action_bw_dec (struct GAS_RIL_Handle *solver,
601 new_bw = agent->bw_in - (5 * min_bw); 668 new_bw = agent->bw_in - (5 * min_bw);
602 if (new_bw < min_bw) 669 if (new_bw < min_bw)
603 new_bw = min_bw; 670 new_bw = min_bw;
604 envi_change_active_address (solver, agent, agent->address, new_bw, 671 envi_set_active_suggestion (solver, agent, agent->address_inuse, new_bw, agent->bw_out);
605 agent->bw_out);
606 } 672 }
607 else 673 else
608 { 674 {
609 new_bw = agent->bw_out - (5 * min_bw); 675 new_bw = agent->bw_out - (5 * min_bw);
610 if (new_bw < min_bw) 676 if (new_bw < min_bw)
611 new_bw = min_bw; 677 new_bw = min_bw;
612 envi_change_active_address (solver, agent, agent->address, agent->bw_in, 678 envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in, new_bw);
613 new_bw);
614 } 679 }
615} 680}
616 681
@@ -620,9 +685,7 @@ envi_action_bw_dec (struct GAS_RIL_Handle *solver,
620 * @param action action to perform by the solver 685 * @param action action to perform by the solver
621 */ 686 */
622static void 687static void
623envi_do_action (struct GAS_RIL_Handle *solver, 688envi_do_action (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int action)
624 struct RIL_Peer_Agent *agent,
625 int action)
626{ 689{
627 switch (action) 690 switch (action)
628 { 691 {
@@ -675,7 +738,7 @@ agent_step (struct RIL_Peer_Agent *agent)
675 s_next = envi_get_state (agent->envi); 738 s_next = envi_get_state (agent->envi);
676 reward = envi_get_reward (agent->envi, agent); 739 reward = envi_get_reward (agent->envi, agent);
677 740
678 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "agent_step() with algorithm %s\n", 741 LOG(GNUNET_ERROR_TYPE_DEBUG, "agent_step() with algorithm %s\n",
679 agent->envi->parameters.algorithm ? "Q" : "SARSA"); 742 agent->envi->parameters.algorithm ? "Q" : "SARSA");
680 743
681 switch (agent->envi->parameters.algorithm) 744 switch (agent->envi->parameters.algorithm)
@@ -737,8 +800,7 @@ ril_periodic_step (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
737 struct GAS_RIL_Handle *solver = cls; 800 struct GAS_RIL_Handle *solver = cls;
738 struct RIL_Peer_Agent *cur; 801 struct RIL_Peer_Agent *cur;
739 802
740 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "RIL step number %d\n", 803 LOG(GNUNET_ERROR_TYPE_DEBUG, "RIL step number %d\n", solver->step_count);
741 solver->step_count);
742 804
743 for (cur = solver->agents_head; NULL != cur; cur = cur->next) 805 for (cur = solver->agents_head; NULL != cur; cur = cur->next)
744 { 806 {
@@ -749,8 +811,7 @@ ril_periodic_step (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
749 } 811 }
750 812
751 solver->step_count += 1; 813 solver->step_count += 1;
752 solver->next_step = GNUNET_SCHEDULER_add_delayed (solver->step_time, 814 solver->next_step = GNUNET_SCHEDULER_add_delayed (solver->step_time, &ril_periodic_step, solver);
753 &ril_periodic_step, solver);
754} 815}
755 816
756/** 817/**
@@ -782,8 +843,7 @@ agent_init (void *s, const struct GNUNET_PeerIdentity *peer)
782 agent->e = (double *) GNUNET_malloc (sizeof (double) * agent->m); 843 agent->e = (double *) GNUNET_malloc (sizeof (double) * agent->m);
783 agent_modify_eligibility (agent, RIL_E_ZERO); 844 agent_modify_eligibility (agent, RIL_E_ZERO);
784 845
785 GNUNET_CONTAINER_DLL_insert_tail(solver->agents_head, solver->agents_tail, 846 GNUNET_CONTAINER_DLL_insert_tail(solver->agents_head, solver->agents_tail, agent);
786 agent);
787 847
788 return agent; 848 return agent;
789} 849}
@@ -807,50 +867,6 @@ agent_die (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
807 GNUNET_free(agent->s_old); 867 GNUNET_free(agent->s_old);
808} 868}
809 869
810static void
811ril_remove_agent (struct GAS_RIL_Handle *s, struct RIL_Peer_Agent *agent)
812{
813 struct RIL_Peer_Agent *cur_agent;
814 struct RIL_Peer_Agent *next_agent;
815
816 cur_agent = s->agents_head;
817 while (NULL != cur_agent)
818 {
819 next_agent = cur_agent->next;
820
821 if (agent == cur_agent)
822 {
823 GNUNET_CONTAINER_DLL_remove(s->agents_head, s->agents_tail, cur_agent);
824 agent_die (s, cur_agent);
825 }
826
827 cur_agent = next_agent;
828 }
829}
830
831/**
832 * Counts the (active) agents
833 * @param solver solver handle
834 * @param active_only whether only active agents should be counted
835 * @return number of agents
836 */
837//static int
838//ril_count_agents (struct GAS_RIL_Handle *solver, int active_only)
839//{
840// int c;
841// struct RIL_Peer_Agent *cur;
842//
843// c = 0;
844// for (cur = solver->agents_head; NULL != cur; cur = cur->next)
845// {
846// if ((!active_only) || (active_only && cur->active))
847// {
848// c += 1;
849// }
850// }
851// return c;
852//}
853
854/** 870/**
855 * Returns the agent for a peer 871 * Returns the agent for a peer
856 * @param s solver handle 872 * @param s solver handle
@@ -859,9 +875,7 @@ ril_remove_agent (struct GAS_RIL_Handle *s, struct RIL_Peer_Agent *agent)
859 * @return agent 875 * @return agent
860 */ 876 */
861static struct RIL_Peer_Agent * 877static struct RIL_Peer_Agent *
862ril_get_agent (struct GAS_RIL_Handle *solver, 878ril_get_agent (struct GAS_RIL_Handle *solver, const struct GNUNET_PeerIdentity *peer, int create)
863 const struct GNUNET_PeerIdentity *peer,
864 int create)
865{ 879{
866 struct RIL_Peer_Agent *cur; 880 struct RIL_Peer_Agent *cur;
867 881
@@ -878,93 +892,74 @@ ril_get_agent (struct GAS_RIL_Handle *solver,
878 return NULL ; 892 return NULL ;
879} 893}
880 894
881static int
882ril_network_is_active (struct RIL_Network *network)
883{
884 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
885
886 if (network->bw_out_available < min_bw)
887 return GNUNET_NO;
888 return GNUNET_YES;
889}
890
891/** 895/**
892 * Iterator, which allocates one agent per peer 896 * Lookup network struct by type
893 * 897 *
894 * @param cls solver 898 * @param s the solver handle
895 * @param key peer identity 899 * @param type the network type
896 * @param value address 900 * @return the network struct
897 * @return whether iterator should continue
898 */ 901 */
899static int 902static struct RIL_Network *
900ril_init_agents_it (void *cls, const struct GNUNET_HashCode *key, void *value) 903ril_get_network (struct GAS_RIL_Handle *s, uint32_t type)
901{ 904{
902 struct GAS_RIL_Handle *solver = cls; 905 int i;
903 struct ATS_Address *address = value;
904 struct RIL_Peer_Agent *agent = NULL;
905 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
906 906
907 if (ril_network_is_active (address->solver_information)) 907 for (i = 0; i < s->networks_count; i++)
908 { 908 {
909 agent = ril_get_agent (solver, &address->peer, GNUNET_YES); 909 if (s->network_entries[i].type == type)
910
911 GNUNET_assert(NULL != agent);
912
913 if (NULL == agent->address)
914 { 910 {
915 agent->address = address; 911 return &s->network_entries[i];
916 agent->address->active = GNUNET_YES;
917 agent->bw_in = min_bw;
918 agent->address->assigned_bw_in.value__ = htonl (min_bw);
919 agent->bw_out = min_bw;
920 agent->address->assigned_bw_out.value__ = htonl (min_bw);
921 } 912 }
922 } 913 }
914 return NULL ;
915}
916
917static int
918ril_network_is_active (struct GAS_RIL_Handle *solver, enum GNUNET_ATS_Network_Type network)
919{
920 struct RIL_Network *net;
921 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
922
923 net = ril_get_network(solver, network);
924 if (net->bw_out_available < min_bw)
925 return GNUNET_NO;
923 return GNUNET_YES; 926 return GNUNET_YES;
924} 927}
925 928
926static void 929static void
927ril_get_new_address_or_delete (struct GAS_RIL_Handle *solver, 930ril_cut_from_vector (void **old, size_t element_size, unsigned int hole_start, unsigned int hole_length, unsigned int old_length)
928 struct RIL_Peer_Agent *agent)
929{ 931{
930 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__); 932 char *tmpptr;
931 //get new address for agent or delete agent 933 char *oldptr = (char *) *old;
934 size_t size;
935 unsigned int bytes_before;
936 unsigned int bytes_hole;
937 unsigned int bytes_after;
932 938
933 agent->address = NULL; //forget current address 939 GNUNET_assert(old_length > hole_length);
934 GNUNET_CONTAINER_multihashmap_iterate (solver->addresses, &ril_init_agents_it, 940 GNUNET_assert(old_length > (hole_start + hole_length - 1));
935 solver); //put another address
936 941
937 if (NULL == agent->address) //no other address available 942 size = (old_length - hole_length) * element_size;
943
944 bytes_before = element_size * hole_start;
945 bytes_hole = element_size * hole_length;
946 bytes_after = element_size * (old_length - hole_start - hole_length);
947
948 if (0 == size)
938 { 949 {
939 agent->active = GNUNET_NO; 950 tmpptr = NULL;
940 ril_remove_agent (solver, agent);
941 } 951 }
942 else 952 else
943 { 953 {
944 envi_change_active_address (solver, agent, agent->address, min_bw, min_bw); 954 tmpptr = GNUNET_malloc (size);
955 memcpy (tmpptr, oldptr, bytes_before);
956 memcpy (tmpptr + bytes_before, oldptr + (bytes_before + bytes_hole), bytes_after);
945 } 957 }
946} 958 if (NULL != *old)
947
948/**
949 * Lookup network struct by type
950 *
951 * @param s the solver handle
952 * @param type the network type
953 * @return the network struct
954 */
955static struct RIL_Network *
956ril_get_network (struct GAS_RIL_Handle *s, uint32_t type)
957{
958 int i;
959
960 for (i = 0; i < s->networks_count; i++)
961 { 959 {
962 if (s->network_entries[i].type == type) 960 GNUNET_free(*old);
963 {
964 return &s->network_entries[i];
965 }
966 } 961 }
967 return NULL ; 962 *old = (void *) tmpptr;
968} 963}
969 964
970/** 965/**
@@ -986,7 +981,7 @@ GAS_ril_address_change_preference (void *s,
986 enum GNUNET_ATS_PreferenceKind kind, 981 enum GNUNET_ATS_PreferenceKind kind,
987 double pref_rel) 982 double pref_rel)
988{ 983{
989 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 984 LOG(GNUNET_ERROR_TYPE_DEBUG,
990 "API_address_change_preference() Preference '%s' for peer '%s' changed to %.2f \n", 985 "API_address_change_preference() Preference '%s' for peer '%s' changed to %.2f \n",
991 GNUNET_ATS_print_preference_type (kind), GNUNET_i2s (peer), pref_rel); 986 GNUNET_ATS_print_preference_type (kind), GNUNET_i2s (peer), pref_rel);
992 /* 987 /*
@@ -1044,7 +1039,7 @@ GAS_ril_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
1044 struct RIL_Network * cur; 1039 struct RIL_Network * cur;
1045 struct GAS_RIL_Handle *solver = GNUNET_malloc (sizeof (struct GAS_RIL_Handle)); 1040 struct GAS_RIL_Handle *solver = GNUNET_malloc (sizeof (struct GAS_RIL_Handle));
1046 1041
1047 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "API_init() Initializing RIL solver\n"); 1042 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_init() Initializing RIL solver\n");
1048 1043
1049 GNUNET_assert(NULL != cfg); 1044 GNUNET_assert(NULL != cfg);
1050 GNUNET_assert(NULL != stats); 1045 GNUNET_assert(NULL != stats);
@@ -1054,14 +1049,12 @@ GAS_ril_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
1054 GNUNET_assert(NULL != get_properties); 1049 GNUNET_assert(NULL != get_properties);
1055 1050
1056 if (GNUNET_OK 1051 if (GNUNET_OK
1057 != GNUNET_CONFIGURATION_get_value_time (cfg, "ats", "RIL_STEP_TIME", 1052 != GNUNET_CONFIGURATION_get_value_time (cfg, "ats", "RIL_STEP_TIME", &solver->step_time))
1058 &solver->step_time))
1059 { 1053 {
1060 solver->step_time = RIL_DEFAULT_STEP_TIME; 1054 solver->step_time = RIL_DEFAULT_STEP_TIME;
1061 } 1055 }
1062 if (GNUNET_OK 1056 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, "ats", "RIL_ALGORITHM", &string)
1063 == GNUNET_CONFIGURATION_get_value_string (cfg, "ats", "RIL_ALGORITHM", 1057 && NULL != string && 0 == strcmp (string, "SARSA"))
1064 &string) && NULL != string && 0 == strcmp (string, "SARSA"))
1065 { 1058 {
1066 solver->parameters.algorithm = RIL_ALGO_SARSA; 1059 solver->parameters.algorithm = RIL_ALGO_SARSA;
1067 } 1060 }
@@ -1069,9 +1062,7 @@ GAS_ril_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
1069 { 1062 {
1070 solver->parameters.algorithm = RIL_DEFAULT_ALGORITHM; 1063 solver->parameters.algorithm = RIL_DEFAULT_ALGORITHM;
1071 } 1064 }
1072 if (GNUNET_OK 1065 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", "RIL_DISCOUNT_FACTOR", &tmp))
1073 == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", "RIL_DISCOUNT_FACTOR",
1074 &tmp))
1075 { 1066 {
1076 solver->parameters.gamma = (double) tmp / 100; 1067 solver->parameters.gamma = (double) tmp / 100;
1077 } 1068 }
@@ -1079,9 +1070,7 @@ GAS_ril_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
1079 { 1070 {
1080 solver->parameters.gamma = RIL_DEFAULT_DISCOUNT_FACTOR; 1071 solver->parameters.gamma = RIL_DEFAULT_DISCOUNT_FACTOR;
1081 } 1072 }
1082 if (GNUNET_OK 1073 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", "RIL_GRADIENT_STEP_SIZE", &tmp))
1083 == GNUNET_CONFIGURATION_get_value_size (cfg, "ats",
1084 "RIL_GRADIENT_STEP_SIZE", &tmp))
1085 { 1074 {
1086 solver->parameters.alpha = (double) tmp / 100; 1075 solver->parameters.alpha = (double) tmp / 100;
1087 } 1076 }
@@ -1089,9 +1078,7 @@ GAS_ril_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
1089 { 1078 {
1090 solver->parameters.alpha = RIL_DEFAULT_GRADIENT_STEP_SIZE; 1079 solver->parameters.alpha = RIL_DEFAULT_GRADIENT_STEP_SIZE;
1091 } 1080 }
1092 if (GNUNET_OK 1081 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", "RIL_TRACE_DECAY", &tmp))
1093 == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", "RIL_TRACE_DECAY",
1094 &tmp))
1095 { 1082 {
1096 solver->parameters.lambda = (double) tmp / 100; 1083 solver->parameters.lambda = (double) tmp / 100;
1097 } 1084 }
@@ -1109,8 +1096,7 @@ GAS_ril_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
1109 solver->callbacks->get_properties = get_properties; 1096 solver->callbacks->get_properties = get_properties;
1110 solver->callbacks->get_properties_cls = get_properties_cls; 1097 solver->callbacks->get_properties_cls = get_properties_cls;
1111 solver->networks_count = dest_length; 1098 solver->networks_count = dest_length;
1112 solver->network_entries = 1099 solver->network_entries = GNUNET_malloc (dest_length * sizeof (struct RIL_Network));
1113 GNUNET_malloc (dest_length * sizeof (struct RIL_Network));
1114 solver->bulk_lock = GNUNET_NO; 1100 solver->bulk_lock = GNUNET_NO;
1115 solver->addresses = addresses; 1101 solver->addresses = addresses;
1116 solver->step_count = 0; 1102 solver->step_count = 0;
@@ -1126,8 +1112,8 @@ GAS_ril_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
1126 } 1112 }
1127 1113
1128 solver->next_step = GNUNET_SCHEDULER_add_delayed ( 1114 solver->next_step = GNUNET_SCHEDULER_add_delayed (
1129 GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_get_millisecond_ (), 1115 GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_get_millisecond_ (), 1000),
1130 1000), &ril_periodic_step, solver); 1116 &ril_periodic_step, solver);
1131 1117
1132 return solver; 1118 return solver;
1133} 1119}
@@ -1144,7 +1130,7 @@ GAS_ril_done (void * solver)
1144 struct RIL_Peer_Agent *cur_agent; 1130 struct RIL_Peer_Agent *cur_agent;
1145 struct RIL_Peer_Agent *next_agent; 1131 struct RIL_Peer_Agent *next_agent;
1146 1132
1147 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "API_done() Shutting down RIL solver\n"); 1133 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_done() Shutting down RIL solver\n");
1148 1134
1149 cur_agent = s->agents_head; 1135 cur_agent = s->agents_head;
1150 while (NULL != cur_agent) 1136 while (NULL != cur_agent)
@@ -1169,32 +1155,73 @@ GAS_ril_done (void * solver)
1169 * @param network network type of this address 1155 * @param network network type of this address
1170 */ 1156 */
1171void 1157void
1172GAS_ril_address_add (void *solver, 1158GAS_ril_address_add (void *solver, struct ATS_Address *address, uint32_t network)
1173 struct ATS_Address *address,
1174 uint32_t network)
1175{ 1159{
1176 struct GAS_RIL_Handle *s = solver; 1160 struct GAS_RIL_Handle *s = solver;
1177 //TODO! implement solver address add 1161 struct RIL_Peer_Agent *agent;
1178 /* 1162 struct RIL_Address_Wrapped *address_wrapped;
1179 * if (new peer) 1163 unsigned int m_new;
1180 * initialize new agent 1164 unsigned int m_old;
1181 * Add address 1165 unsigned int n_new;
1182 * increase state vector 1166 unsigned int n_old;
1183 * knowledge matrix 1167 int i;
1184 * and action vector 1168 unsigned int zero;
1185 */ 1169 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
1186 1170
1187 address->solver_information = ril_get_network (s, network); 1171 address->solver_information = ril_get_network (s, network);
1188 1172
1189 /* 1173 if (!ril_network_is_active(s, network))
1190 * reiterate all addresses, create new agent if necessary and give the agent the address 1174 {
1191 */ 1175 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_add() Did not add %s address %p for peer '%s', network does not have enough bandwidth\n",
1192 GNUNET_CONTAINER_multihashmap_iterate (s->addresses, &ril_init_agents_it, 1176 address->plugin, address->addr, GNUNET_i2s (&address->peer));
1193 solver); 1177 return;
1178 }
1179
1180 agent = ril_get_agent(s, &address->peer, GNUNET_YES);
1181
1182 //add address
1183 address_wrapped = GNUNET_malloc (sizeof (struct RIL_Address_Wrapped));
1184 address_wrapped->address_naked = address;
1185 GNUNET_CONTAINER_DLL_insert_tail(agent->addresses_head, agent->addresses_tail, address_wrapped);
1186
1187 //increase size of W
1188 m_new = agent->m + 5; //TODO! make size of features from address variable (Note to self: ctrl+f for "5" or I kill you!)
1189 m_old = agent->m;
1190 n_new = agent->n + 1;
1191 n_old = agent->n;
1192
1193 GNUNET_array_grow (agent->W, agent->n, n_new);
1194 for (i = 0; i < n_new; i++)
1195 {
1196 if (i < n_old)
1197 {
1198 agent->m = m_old;
1199 GNUNET_array_grow(agent->W[i], agent->m, m_new);
1200 }
1201 else
1202 {
1203 zero = 0;
1204 GNUNET_array_grow(agent->W[i], zero, m_new);
1205 }
1206 }
1207
1208 //increase size of old state vector if there is one
1209 if (-1 != agent->a_old)
1210 {
1211 agent->m = m_old;
1212 GNUNET_array_grow(agent->s_old, agent->m, m_new); //TODO initialize new state features?
1213 }
1214
1215 agent->m = m_old;
1216 GNUNET_array_grow(agent->e, agent->m, m_new);
1217
1218 if (NULL == agent->address_inuse)
1219 {
1220 envi_set_active_suggestion(s, agent, address, min_bw, min_bw);
1221 }
1194 1222
1195 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1223 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_add() Added %s address %p for peer '%s'\n",
1196 "API_address_add() Added %s address for peer '%s'\n", address->plugin, 1224 address->plugin, address->addr, GNUNET_i2s (&address->peer));
1197 GNUNET_i2s (&address->peer));
1198} 1225}
1199 1226
1200/** 1227/**
@@ -1205,48 +1232,70 @@ GAS_ril_address_add (void *solver,
1205 * @param session_only delete only session not whole address 1232 * @param session_only delete only session not whole address
1206 */ 1233 */
1207void 1234void
1208GAS_ril_address_delete (void *solver, 1235GAS_ril_address_delete (void *solver, struct ATS_Address *address, int session_only)
1209 struct ATS_Address *address,
1210 int session_only)
1211{ 1236{
1212 //TODO! implement solver address delete
1213 //TODO! delete session only 1237 //TODO! delete session only
1214 /*
1215 * remove address
1216 * if (last address of peer)
1217 * remove agent
1218 * else
1219 * decrease state vector
1220 * decrease knowledge matrix
1221 * decrease action vector
1222 */
1223 struct GAS_RIL_Handle *s = solver; 1238 struct GAS_RIL_Handle *s = solver;
1224 struct RIL_Peer_Agent *agent; 1239 struct RIL_Peer_Agent *agent;
1240 struct RIL_Address_Wrapped *address_wrapped;
1241 int address_was_used = address->active;
1242 int address_index;
1243 unsigned int m_new;
1244 unsigned int n_new;
1245 int i;
1246 struct RIL_Network *net;
1247 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
1225 1248
1226 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1249 agent = ril_get_agent(s, &address->peer, GNUNET_NO);
1227 "API_address_delete() deleting %s address %p for peer '%s'\n", 1250 if (NULL == agent)
1228 address->active ? "active" : "inactive", address, 1251 {
1229 GNUNET_i2s (&address->peer)); 1252 LOG (GNUNET_ERROR_TYPE_DEBUG, "No agent allocated for peer\n");
1253 }
1230 1254
1231 agent = ril_get_agent (s, &address->peer, GNUNET_NO); 1255 address_index = agent_address_get_index(agent, address);
1256 address_wrapped = agent_address_get(agent, address);
1232 1257
1233 if (NULL == agent) 1258 GNUNET_CONTAINER_DLL_remove(agent->addresses_head, agent->addresses_tail, address_wrapped);
1259
1260 //decrease W
1261 m_new = agent->m - 5;
1262 n_new = agent->n - 1;
1263
1264 for (i = 0; i < agent->n; i++)
1234 { 1265 {
1235 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1266 ril_cut_from_vector((void **) &agent->W[i], sizeof (double), ((s->networks_count * 4) + (i * 5)), 5, agent->m);
1236 "API_address_delete() deleting address for unallocated agent\n"); 1267 }
1237 return; 1268 ril_cut_from_vector((void **) &agent->W, sizeof (double *), RIL_ACTION_TYPE_NUM + address_index, 1, agent->n);
1269 //correct last action
1270 if (agent->a_old > (RIL_ACTION_TYPE_NUM + address_index))
1271 {
1272 agent->a_old -= 1;
1238 } 1273 }
1274 else if (agent->a_old == (RIL_ACTION_TYPE_NUM + address_index))
1275 {
1276 agent->a_old = -1; //TODO! macro for invalid action
1277 }
1278 //decrease old state vector and eligibility vector
1279 ril_cut_from_vector((void **) &agent->s_old, sizeof (double), ((s->networks_count * 4) + (i * 5)), 5, agent->m);
1280 ril_cut_from_vector((void **) &agent->e, sizeof (double), ((s->networks_count * 4) + (i * 5)), 5, agent->m);
1281 agent->m = m_new;
1282 agent->n = n_new;
1239 1283
1240 if (address == agent->address) //if used address deleted 1284 if (address_was_used)
1241 { 1285 {
1242 address->active = GNUNET_NO; 1286 net = address->solver_information;
1243 ril_get_new_address_or_delete (s, agent); 1287 net->bw_in_assigned -= agent->bw_in;
1288 net->bw_out_assigned -= agent->bw_out;
1289
1290 //TODO? check if network/bandwidth update can be done more clever/elegant at different function
1291 envi_set_active_suggestion(s, agent, agent->addresses_head->address_naked, min_bw, min_bw);
1292 net = agent->addresses_head->address_naked->solver_information;
1293 net->bw_in_assigned -= min_bw;
1294 net->bw_out_assigned -= min_bw;
1244 } 1295 }
1245 1296
1246 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1297 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_delete() Deleted %s%s address for peer '%s'\n",
1247 "API_address_delete() Deleted %s%s address for peer '%s'\n", 1298 session_only ? "session for " : "", address->plugin, GNUNET_i2s (&address->peer));
1248 session_only ? "session for " : "", address->plugin,
1249 GNUNET_i2s (&address->peer));
1250} 1299}
1251 1300
1252/** 1301/**
@@ -1265,10 +1314,10 @@ GAS_ril_address_property_changed (void *solver,
1265 uint32_t abs_value, 1314 uint32_t abs_value,
1266 double rel_value) 1315 double rel_value)
1267{ 1316{
1268 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1317 LOG(GNUNET_ERROR_TYPE_DEBUG,
1269 "API_address_property_changed() Property '%s' for peer '%s' address %p changed " 1318 "API_address_property_changed() Property '%s' for peer '%s' address %p changed "
1270 "to %.2f \n", GNUNET_ATS_print_property_type (type), 1319 "to %.2f \n", GNUNET_ATS_print_property_type (type), GNUNET_i2s (&address->peer), address,
1271 GNUNET_i2s (&address->peer), address, rel_value); 1320 rel_value);
1272 /* 1321 /*
1273 * Nothing to do here, properties are considered in every reward calculation 1322 * Nothing to do here, properties are considered in every reward calculation
1274 */ 1323 */
@@ -1294,7 +1343,7 @@ GAS_ril_address_session_changed (void *solver,
1294 /* 1343 /*
1295 * Potentially add session activity as a feature in state vector 1344 * Potentially add session activity as a feature in state vector
1296 */ 1345 */
1297 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "API_address_session_changed()\n"); 1346 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_session_changed()\n");
1298} 1347}
1299 1348
1300/** 1349/**
@@ -1307,18 +1356,15 @@ GAS_ril_address_session_changed (void *solver,
1307 * @param in_use usage state 1356 * @param in_use usage state
1308 */ 1357 */
1309void 1358void
1310GAS_ril_address_inuse_changed (void *solver, 1359GAS_ril_address_inuse_changed (void *solver, struct ATS_Address *address, int in_use)
1311 struct ATS_Address *address,
1312 int in_use)
1313{ 1360{
1314 //TODO! consider address_inuse_changed according to matthias' email 1361 //TODO! consider address_inuse_changed according to matthias' email
1315 /** 1362 /**
1316 * See matthias' email 1363 * See matthias' email
1317 */ 1364 */
1318 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1365 LOG(GNUNET_ERROR_TYPE_DEBUG,
1319 "API_address_inuse_changed() Usage for %s address of peer '%s' changed to %s\n", 1366 "API_address_inuse_changed() Usage for %s address of peer '%s' changed to %s\n",
1320 address->plugin, GNUNET_i2s (&address->peer), 1367 address->plugin, GNUNET_i2s (&address->peer), (GNUNET_YES == in_use) ? "USED" : "UNUSED");
1321 (GNUNET_YES == in_use) ? "USED" : "UNUSED");
1322} 1368}
1323 1369
1324/** 1370/**
@@ -1340,54 +1386,36 @@ GAS_ril_address_change_network (void *solver,
1340 struct GAS_RIL_Handle *s = solver; 1386 struct GAS_RIL_Handle *s = solver;
1341 struct RIL_Peer_Agent *agent; 1387 struct RIL_Peer_Agent *agent;
1342 struct RIL_Network *net; 1388 struct RIL_Network *net;
1389 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
1343 1390
1344 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1391 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_change_network() Network type changed, moving "
1345 "API_address_change_network() Network type changed, moving " 1392 "%s address of peer %s from '%s' to '%s'\n",
1346 "%s address of peer %s from '%s' to '%s'\n", 1393 (GNUNET_YES == address->active) ? "active" : "inactive", GNUNET_i2s (&address->peer),
1347 (GNUNET_YES == address->active) ? "active" : "inactive", 1394 GNUNET_ATS_print_network_type (current_network), GNUNET_ATS_print_network_type (new_network));
1348 GNUNET_i2s (&address->peer),
1349 GNUNET_ATS_print_network_type (current_network),
1350 GNUNET_ATS_print_network_type (new_network));
1351
1352 address->solver_information = ril_get_network (solver, new_network);
1353 1395
1354 if (address->active) 1396 if (address->active && !ril_network_is_active(solver, new_network))
1355 { 1397 {
1356 agent = ril_get_agent (solver, &address->peer, GNUNET_NO); 1398 GAS_ril_address_delete(solver, address, GNUNET_NO);
1357 1399 return;
1358 //remove from old network 1400 }
1359 net = ril_get_network (s, current_network);
1360 net->bw_in_assigned -= agent->bw_in;
1361 net->bw_out_assigned -= agent->bw_out;
1362
1363 if (ril_network_is_active (ril_get_network (s, new_network)))
1364 {
1365 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "New network is active\n");
1366 //add to new network
1367 net = ril_get_network (s, new_network);
1368 net->bw_in_assigned += agent->bw_in;
1369 net->bw_out_assigned += agent->bw_out;
1370
1371 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1372 "API_address_change_network() Moved %d inbound and %d "
1373 "outbound\n", agent->bw_in, agent->bw_out);
1374 }
1375 else //new network for this address is not active => address must not be considered
1376 {
1377 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "New network is not active\n");
1378 1401
1379 net = agent->address->solver_information; 1402 agent = ril_get_agent(s, &address->peer, GNUNET_NO);
1380 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Before: active address %p is %s\n", 1403 if (NULL == agent)
1381 agent->address, GNUNET_ATS_print_network_type (net->type)); 1404 {
1405 //no agent there yet, so add as if address is new
1406 address->solver_information = ril_get_network (s, new_network);
1407 GAS_ril_address_add(s,address,new_network);
1408 return;
1409 }
1382 1410
1383 address->active = GNUNET_NO; 1411 net = ril_get_network (s, current_network);
1384 ril_get_new_address_or_delete (s, agent); 1412 net->bw_in_assigned -= agent->bw_in;
1413 net->bw_out_assigned -= agent->bw_out;
1385 1414
1386 net = agent->address->solver_information; 1415 net = ril_get_network (s, new_network);
1387 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "After: active address %p is %s\n", 1416 net->bw_in_assigned -= min_bw;
1388 agent->address, GNUNET_ATS_print_network_type (net->type)); 1417 net->bw_out_assigned -= min_bw;
1389 } 1418 address->solver_information = net;
1390 }
1391} 1419}
1392 1420
1393/** 1421/**
@@ -1409,7 +1437,7 @@ GAS_ril_address_preference_feedback (void *solver,
1409 double score) 1437 double score)
1410{ 1438{
1411 //TODO! collect reward until next reward calculation 1439 //TODO! collect reward until next reward calculation
1412 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1440 LOG(GNUNET_ERROR_TYPE_DEBUG,
1413 "API_address_preference_feedback() Peer '%s' got a feedback of %+.3f from application %s for " 1441 "API_address_preference_feedback() Peer '%s' got a feedback of %+.3f from application %s for "
1414 "preference %s for %d seconds\n", GNUNET_i2s (peer), "UNKNOWN", 1442 "preference %s for %d seconds\n", GNUNET_i2s (peer), "UNKNOWN",
1415 GNUNET_ATS_print_preference_type (kind), scope.rel_value_us / 1000000); 1443 GNUNET_ATS_print_preference_type (kind), scope.rel_value_us / 1000000);
@@ -1430,7 +1458,7 @@ GAS_ril_bulk_start (void *solver)
1430 * they want. Consideration: Step-pause during bulk-start-stop period... 1458 * they want. Consideration: Step-pause during bulk-start-stop period...
1431 */ 1459 */
1432 1460
1433 //GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "API_bulk_start()\n"); 1461 //LOG(GNUNET_ERROR_TYPE_DEBUG, "API_bulk_start()\n");
1434} 1462}
1435 1463
1436/** 1464/**
@@ -1444,7 +1472,7 @@ GAS_ril_bulk_stop (void *solver)
1444 * bulk counter down, see bulk_start() 1472 * bulk counter down, see bulk_start()
1445 */ 1473 */
1446 1474
1447 //GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "API_bulk_stop()\n"); 1475 //LOG(GNUNET_ERROR_TYPE_DEBUG, "API_bulk_stop()\n");
1448} 1476}
1449 1477
1450/** 1478/**
@@ -1454,8 +1482,7 @@ GAS_ril_bulk_stop (void *solver)
1454 * @param peer the identity of the peer 1482 * @param peer the identity of the peer
1455 */ 1483 */
1456const struct ATS_Address * 1484const struct ATS_Address *
1457GAS_ril_get_preferred_address (void *solver, 1485GAS_ril_get_preferred_address (void *solver, const struct GNUNET_PeerIdentity *peer)
1458 const struct GNUNET_PeerIdentity *peer)
1459{ 1486{
1460 /* 1487 /*
1461 * activate agent, return currently chosen address 1488 * activate agent, return currently chosen address
@@ -1467,7 +1494,7 @@ GAS_ril_get_preferred_address (void *solver,
1467 1494
1468 if (NULL == agent) 1495 if (NULL == agent)
1469 { 1496 {
1470 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1497 LOG(GNUNET_ERROR_TYPE_DEBUG,
1471 "API_get_preferred_address() No agent for peer '%s' do not suggest address\n", 1498 "API_get_preferred_address() No agent for peer '%s' do not suggest address\n",
1472 GNUNET_i2s (peer)); 1499 GNUNET_i2s (peer));
1473 return NULL ; 1500 return NULL ;
@@ -1475,13 +1502,13 @@ GAS_ril_get_preferred_address (void *solver,
1475 1502
1476 agent->active = GNUNET_YES; 1503 agent->active = GNUNET_YES;
1477 1504
1478 GNUNET_assert(NULL != agent->address); 1505 GNUNET_assert(NULL != agent->address_inuse);
1479 1506
1480 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1507 LOG(GNUNET_ERROR_TYPE_DEBUG,
1481 "API_get_preferred_address() Activated agent for peer '%s' with %s address\n", 1508 "API_get_preferred_address() Activated agent for peer '%s' with %s address\n",
1482 GNUNET_i2s (peer), agent->address->plugin); 1509 GNUNET_i2s (peer), agent->address_inuse->plugin);
1483 1510
1484 return agent->address; 1511 return agent->address_inuse;
1485} 1512}
1486 1513
1487/** 1514/**
@@ -1491,8 +1518,7 @@ GAS_ril_get_preferred_address (void *solver,
1491 * @param peer the peer 1518 * @param peer the peer
1492 */ 1519 */
1493void 1520void
1494GAS_ril_stop_get_preferred_address (void *solver, 1521GAS_ril_stop_get_preferred_address (void *solver, const struct GNUNET_PeerIdentity *peer)
1495 const struct GNUNET_PeerIdentity *peer)
1496{ 1522{
1497 struct GAS_RIL_Handle *s = solver; 1523 struct GAS_RIL_Handle *s = solver;
1498 struct RIL_Peer_Agent *agent; 1524 struct RIL_Peer_Agent *agent;
@@ -1500,9 +1526,9 @@ GAS_ril_stop_get_preferred_address (void *solver,
1500 agent = ril_get_agent (s, peer, GNUNET_NO); 1526 agent = ril_get_agent (s, peer, GNUNET_NO);
1501 agent->active = GNUNET_NO; 1527 agent->active = GNUNET_NO;
1502 1528
1503 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1529 LOG(GNUNET_ERROR_TYPE_DEBUG,
1504 "API_stop_get_preferred_address() Paused agent for peer '%s' with %s address\n", 1530 "API_stop_get_preferred_address() Paused agent for peer '%s' with %s address\n",
1505 GNUNET_i2s (peer), agent->address->plugin); 1531 GNUNET_i2s (peer), agent->address_inuse->plugin);
1506} 1532}
1507 1533
1508/* end of gnunet-service-ats-solver_ril.c */ 1534/* end of gnunet-service-ats-solver_ril.c */