Article delegate-en/3106 of [1-5169] on the server localhost:119
  upper oldest olders older1 this newer1 newers latest
search
[Top/Up] [oldest] - [Older+chunk] - [Newer+chunk] - [newest + Check]
[Reference:<_A3102@delegate-en.ML_>]
Newsgroups: mail-lists.delegate-en

[DeleGate-En] Re: delegate 3100
15 Jan 2006 23:39:02 GMT feedback@delegate.org (Yutaka Sato)
The DeleGate Project


Hallo,

In message <_A3102@delegate-en.ML_> on 01/16/06(00:56:33)
you Martin Papadopoulos <payeabdyi-c23u5qlvwonr.ml@ml.delegate.org> wrote:
 |i will give it defenitly a trie !

 |On 01/04/06(16:18) you ppefabdyi.ml@delegate.org wrote
 |in /<_A3098@delegate-en.ML_>/
...
 |Such session can be realized in an application layer protocol, for example
 |using Cookie header in the HTTP protocol (or using Digest-Authentication).
 |The DeleGate can send Set-Cookie:MASTER=Y to a client in response when
 |DeleGateY is selected as a master.  The client will echo Cookie:MASTER=Y
 |in request, then the DeleGate use the DeleGateY without trying DeleGateX.
 |I implemented this scheme and it seems working.  I'll open the patch
 |if you will give it a try.

The extension is as the enclosed patch.
(Current 9.0.6-pre1 is in nasty status including many tentative
patches and probes to be removed before released)

Cheers,
Yutaka
--
  D G   Yutaka Sato <y.sato@delegate.org> http://delegate.org/y.sato/
 ( - )  National Institute of Advanced Industrial Science and Technology
_<   >_ 1-1-4 Umezono, Tsukuba, Ibaraki, 305-8568 Japan
Do the more with the less -- B. Fuller


diff -cr ../delegate9.0.5/src/ddi.c ./src/ddi.c
*** ../delegate9.0.5/src/ddi.c	Sun Dec  4 18:14:40 2005
--- ./src/ddi.c	Mon Jan 16 07:33:29 2006
***************
*** 290,295 ****
--- 290,300 ----
   */
  void clear_DGreq(Connection *Conn)
  {
+ 	extern int MasterXi;
+ 	extern int MasterXo;
+ 	MasterXi = 0;
+ 	MasterXo = 0;
+ 
  	DDI_clearCbuf(Conn);
  	if( headerX ) clear_DGheader(Conn);
  	if( inputsX ) clear_DGinputs(Conn);
diff -cr ../delegate9.0.5/src/http.c ./src/http.c
*** ../delegate9.0.5/src/http.c	Mon Dec  5 06:40:20 2005
--- ./src/http.c	Mon Jan 16 08:22:41 2006
***************
*** 1372,1377 ****
--- 1372,1420 ----
  	}
  }
  
+ extern int MasterXi;
+ extern int MasterXo;
+ static const char *DGC_MASTER = "DeleGate-Control-MASTER";
+ extern const char *TIMEFORM_COOKIE;
+ 
+ static int getDGC_ROUTE(Connection *Conn,PCStr(cookie)){
+ 	int len = strlen(DGC_MASTER);
+ 	const char *dp;
+ 	const char *id = DeleGateId();
+ 	if( !strneq(cookie,DGC_MASTER,len) )
+ 		return 0;
+ 	dp = cookie+len;
+ 	if( *dp++ != '-' )
+ 		return 0;
+ 	if( !strneq(dp,id,strlen(id)) )
+ 		return 0;
+ 	dp += strlen(id);
+ 	if( *dp++ != '=' )
+ 		return 0;
+ 	sv1log("MasterXi=%d [%s]\n",atoi(dp),cookie);
+ 	MasterXi = atoi(dp);
+ 	return 1;
+ }
+ static int putDGC_ROUTE(Connection *Conn,FILE *tc){
+ 	int exp;
+ 	CStr(ex,128);
+ 	CStr(cookie,128);
+ 	int nput = 0;
+ 
+ 	if( 0 < MasterXo ) /* MASTER is applied in this connection */
+ 	if( MasterXi != MasterXo )
+ 	{
+ 		exp = time(0) + 10*60;
+ 		StrftimeGMT(AVStr(ex),sizeof(ex),TIMEFORM_COOKIE,exp,0);
+ 		sprintf(cookie,"%s-%s=%d",DGC_MASTER,DeleGateId(),MasterXo);
+ 		Xsprintf(TVStr(cookie),"; Expires=%s",ex);
+ 		sv1log("MasterXi=%d -> MasterXo=%d\n",MasterXi,MasterXo);
+ 		fprintf(tc,"Set-Cookie: %s\r\n",cookie);
+ 		nput++;
+ 	}
+ 	return nput;
+ }
+ 
  /*
   * do something before ending response header
   * with empty CRLF line
***************
*** 1380,1385 ****
--- 1423,1429 ----
  {	CStr(via,256);
  	CStr(head,256);
  
+ 	putDGC_ROUTE(Conn,RX_tcp);
  	if( !ClientEOF && RX_qWithHeader ){
  		head[0] = 0;
  		if( HTTP_genhead(Conn,AVStr(head),KH_OUT|KH_RES) )
***************
*** 4465,4470 ****
--- 4509,4517 ----
  			CStr(cookie,256);
  			getProxyCookie(Conn,QX,AVStr(req));
  			lineScan(req+7,cookie);
+ 			if( getDGC_ROUTE(Conn,cookie) ){
+ 				continue;
+ 			}
  			if( strncmp(cookie,"DeleGate-Control=",17) == 0 ){
  				sv1log("#Proxy-Cookie: %s",req);
  				lineScan(cookie+17,proxyCookie);
diff -cr ../delegate9.0.5/src/master.c ./src/master.c
*** ../delegate9.0.5/src/master.c	Sun Nov  6 06:17:36 2005
--- ./src/master.c	Mon Jan 16 07:37:00 2006
***************
*** 1838,1843 ****
--- 1838,1844 ----
  extern int FromTeleport;
  extern int MASTER_ROUND_ROBIN;
  int SERNO();
+ int nMASTERS(){ return MasterX; }
  int DELEGATE_master(int ms,const char **master,int *mport,int *teleport,int *cacheonly)
  {	int mn,mi;
  	Route *Rp;
diff -cr ../delegate9.0.5/src/service.c ./src/service.c
*** ../delegate9.0.5/src/service.c	Wed Nov  2 08:21:28 2005
--- ./src/service.c	Sun Jan 15 03:58:21 2006
***************
*** 2148,2156 ****
--- 2148,2161 ----
  int DELEGATE_Filter(int mi,PCStr(dstproto),PCStr(dsthost),int dstport);
  int DELEGATE_master(int ms,const char **master,int *mport,int *teleport,int *cacheonly);
  
+ int MasterXi;
+ int MasterXo;
+ int nMASTERS();
+ 
  int open_master(Connection *Conn,int try_direct,PCStr(server),int svport,int sendhead,int relay_input)
  {	int msock;
  	int mi,mx;
+ 	int mn,mi0;
  	const char *master;
  	int no_socks;
  	int mport;
***************
*** 2173,2179 ****
--- 2178,2191 ----
  
  	msock = -1;
  
+ 	/*
  	for(mi = 0; ;mi++){
+ 	*/
+ 	if( 1 < MasterXi ){
+ 		mi0 = MasterXi-1;
+ 	}else	mi0 = 0;
+ 	for( mn = 0; mn < nMASTERS(); mn++ ){
+ 		mi = (mi0 + mn) % nMASTERS(); 
  		if( (mx = DELEGATE_master(mi,&master,&mport,&tport,&cache_only)) == 0 ){
  			msock = -1;
  			goto EXIT;
***************
*** 2227,2232 ****
--- 2239,2245 ----
  			if( connect_master(Conn,mx,msock,cache_only,relay_input) == 0 ){
  				if( tport ) toMaster = 2; else
  				toMaster = 1;
+ 				MasterXo = mi+1;
  				break;
  			}
  			close(msock);

  admin search upper oldest olders older1 this newer1 newers latest
[Top/Up] [oldest] - [Older+chunk] - [Newer+chunk] - [newest + Check]
@_@V