Exemplo n.º 1
0
bool TreeSocket::ComparePass(const Link& link, const std::string &theirs)
{
	this->auth_fingerprint = !link.Fingerprint.empty();
	this->auth_challenge = !ourchallenge.empty() && !theirchallenge.empty();

	const char* fp = NULL;
	if (GetHook())
		fp = BufferedSocketFingerprintRequest(this, Utils->Creator, GetHook()).Send();

	if (fp)
		ServerInstance->Logs->Log("m_spanningtree", DEFAULT, std::string("Server SSL fingerprint ") + fp);

	if (auth_fingerprint)
	{
		/* Require fingerprint to exist and match */
		if (!fp || link.Fingerprint != std::string(fp))
			return false;
	}

	if (auth_challenge)
	{
		std::string our_hmac = MakePass(link.RecvPass, ourchallenge);

		/* Straight string compare of hashes */
		return our_hmac == theirs;
	}

	/* Straight string compare of plaintext */
	return link.RecvPass == theirs;
}
Exemplo n.º 2
0
/* UpdateTMVars: use acc values to calc new estimate of variances */
void UpdateTMVars(void)
{
   int s,m,k,l,M,vSize;
   float occim,x,muDiffk,muDiffl;
   Vector minV;
   VaAcc *va;
   MuAcc *ma;
   MixPDF *mpdf;
   Vector mean;
   Covariance cov;
   Boolean mixFloored,shared;

   for (s=1;s<=nStreams;s++){
      vSize = hset.swidth[s];
      minV = vFloor[s];
      M = hset.tmRecs[s].nMix;
      for (m=1;m<=M;m++){
         mpdf = hset.tmRecs[s].mixes[m];
         cov = mpdf->cov;
         va = (VaAcc *) GetHook(cov.var);
         mean = mpdf->mean;
         ma = (MuAcc *) GetHook(mean);     
         if (va != NULL){
            occim = va->occ;
            mixFloored = FALSE;
            if (occim > 0.0){
               shared=(GetUse(cov.var)>1 || ma==NULL || ma->occ<=0.0);
               if ((mpdf->ckind==DIAGC)||(mpdf->ckind==INVDIAGC))
                  for (k=1; k<=vSize; k++){
                     muDiffk=(shared)?0.0:ma->mu[k]/ma->occ;
                     x = va->cov.var[k]/occim - muDiffk*muDiffk;
                     if (x<minV[k]) {
                        x = minV[k];
                        mixFloored = TRUE;
                     }
                     cov.var[k] = x;
                  }
               else { /* FULLC */
                  for (k=1; k<=vSize; k++){
                     muDiffk=(shared)?0.0:ma->mu[k]/ma->occ;
                     for (l=1; l<=k; l++){
                        muDiffl=(shared)?0.0:ma->mu[l]/ma->occ;
                        x = va->cov.inv[k][l]/occim - muDiffk*muDiffl;
                        if (k==l && x<minV[k]){
                           x = minV[k];
                           mixFloored = TRUE;
                        }              
                        cov.inv[k][l] = x;
                     }
                  }
                  CovInvert(cov.inv,cov.inv);
               }
            }
            else
               HError(-2427,"UpdateTMVars: No use of var %d in stream %d",m,s);
            SetHook(cov.var,NULL);
         }
      }
   }
}
Exemplo n.º 3
0
/* UpdateParameters: in hmm using counts in accumulators */
void UpdateParameters(void)
{
   HMMScanState hss;
   int size;
   StreamInfo *sti;
   WtAcc *wa;
   MuAcc *ma = NULL;
   VaAcc *va;
   TrAcc *ta;
   Boolean hFound = FALSE,shared;

   NewHMMScan(&hset,&hss);
   do if (hmmLink == hss.hmm){
      hFound = TRUE;
      while (GoNextState(&hss,TRUE)) {
         while (GoNextStream(&hss,TRUE)) {
            sti = hss.sti;
            if (hss.M>1 && (uFlags&UPMIXES)){
               wa = (WtAcc *)sti->hook;
               if (hset.hsKind == DISCRETEHS)
                  UpDProbs(hss.i,hss.s,hss.M,wa,sti->spdf.dpdf);
               else
                  UpWeights(hss.i,hss.s,hss.M,wa,sti);
            }
            if (hss.isCont && (uFlags&(UPMEANS|UPVARS)))/*PLAINHS or SHAREDHS*/
               while (GoNextMix(&hss,TRUE)) {
                  size = VectorSize(hss.mp->mean);
                  if (!IsSeenV(hss.mp->mean)) {
                     ma = (MuAcc *)GetHook(hss.mp->mean);
                     if (ma->occ!=0.0)
                     UpMeans(hss.i,hss.s,hss.m,size,ma,hss.mp->mean);
                     /* NB old mean left in ma->mu */
                     TouchV(hss.mp->mean);
                  }
                  if (!IsSeenV(hss.mp->cov.var)) {
                     if (uFlags&UPVARS) {
                        va = (VaAcc *)GetHook(hss.mp->cov.var);
                        shared = (GetUse(hss.mp->cov.var) > 1) ? TRUE:FALSE;
                        if (va->occ!=0.0)
                           UpVars(hss.i,hss.s,hss.m,size,va,ma->mu,hss.mp->mean,shared,hss.mp);
                     }
                     TouchV(hss.mp->cov.var);
                  }
               }
         }
      }
      if (!IsSeenV(hmmLink->transP)) {
         if (uFlags&UPTRANS){
            ta = (TrAcc *)GetHook(hmmLink->transP);
            UpTrans(ta,hmmLink->transP);
         }
         TouchV(hmmLink->transP);       
      }
   } while (!hFound && GoNextHMM(&hss));
   EndHMMScan(&hss);
   if (!hFound)
      HError(2129,"UpdateParameters: hmm not found");
}
Exemplo n.º 4
0
         strcpy(datafn1,GetStrArg());

         datafn = datafn1;

         

         datafn2 = GetStrArg();

      }else

         datafn = GetStrArg();

      if (parMode==0){

         src=LoadAccs(&hset, datafn,uFlags);

         ReadFloat(&src,&tmpFlt,1,ldBinary);

         totalPr += (LogDouble)tmpFlt;

         ReadInt(&src,&tmpInt,1,ldBinary);

         totalT += tmpInt;

         CloseSource( &src );

      }
Exemplo n.º 5
0
/* UpdateMeans: use acc values to calc new estimate of means */
static int UpdateMeans(HMMSet *hset, int px, HLink hmm)
{
   int i,s,m,k,M,N,vSize,nmapped;
   float occim;
   MuAcc *ma;
   StateElem *se;
   StreamElem *ste;
   MixtureElem *me;
   Vector mean;
   
   N = hmm->numStates; nmapped=0;
   se = hmm->svec+2; 
   for (i=2; i<N; i++,se++){
      ste = se->info->pdf+1; 
      for (s=1;s<=S;s++,ste++){
         vSize = hset->swidth[s];
         me = ste->spdf.cpdf + 1; M = ste->nMix;
         for (m=1;m<=M;m++,me++)
            if (MixWeight(hset,me->weight) > MINMIX){
               mean = me->mpdf->mean;
               ma = (MuAcc*)GetHook(mean);
               if (ma != NULL){
                  occim = ma->occ;
                  if (occim > 0.0) {
		    if (occim > minObs) nmapped++;
		    for (k=1; k<=vSize; k++)
		      mean[k] = ( mean[k] * mapTau + (ma->mu[k] + mean[k]*occim) )/( mapTau + occim );
                  } 
                  SetHook(mean,NULL);
               }
            }
      }
   }
   return(nmapped);
}
Exemplo n.º 6
0
bottom_panel(PANEL * pan)
{
  int err = OK;

  T((T_CALLED("bottom_panel(%p)"), (void *)pan));
  if (pan)
    {
      GetHook(pan);
      if (!Is_Bottom(pan))
	{

	  dBug(("--> bottom_panel %s", USER_PTR(pan->user)));

	  HIDE_PANEL(pan, err, OK);
	  assert(_nc_bottom_panel == _nc_stdscr_pseudo_panel);

	  dStack("<lb%d>", 1, pan);

	  pan->below = _nc_bottom_panel;
	  pan->above = _nc_bottom_panel->above;
	  if (pan->above)
	    pan->above->below = pan;
	  _nc_bottom_panel->above = pan;

	  dStack("<lb%d>", 9, pan);
	}
    }
  else
    err = ERR;

  returnCode(err);
}
Exemplo n.º 7
0
/* EXPORT->GetMacroHook: Return value of hook field for any macro */
Ptr GetMacroHook(MLink ml)
{
   Ptr hook;

   switch(ml->type) {
      case 'l': /* HLink */
      case 'h': /* HLink */
         hook=((HLink)(ml->structure))->hook; break;
      case 's': /* StateInfo * */
         hook=((StateInfo *)(ml->structure))->hook; break;
      case 'm': /* MixPDF * */
         hook=((MixPDF *)(ml->structure))->hook; break;
      case 'c': /* STriMat */
      case 'i': /* STriMat */
      case 'x': /* SMatrix */
      case 't': /* SMatrix */
      case 'u': /* SVector */
      case 'd': /* SVector */
      case 'w': /* SVector */
      case 'v': /* SVector */
         hook=GetHook(ml->structure); break;
      case '*': /* deleted */
         hook=NULL; break;
      case 'o': /* fake */
      default:
         hook=NULL;
         HError(7270,"GetMacroHook: Getting hook of non-existant macro");
   }
   return(hook);
}
Exemplo n.º 8
0
show_panel(PANEL * pan)
{
  int err = ERR;

  T((T_CALLED("show_panel(%p)"), (void *)pan));

  if (pan)
    {
      GetHook(pan);

      if (Is_Top(pan))
	returnCode(OK);

      dBug(("--> show_panel %s", USER_PTR(pan->user)));

      HIDE_PANEL(pan, err, OK);

      dStack("<lt%d>", 1, pan);
      assert(_nc_bottom_panel == _nc_stdscr_pseudo_panel);

      _nc_top_panel->above = pan;
      pan->below = _nc_top_panel;
      pan->above = (PANEL *) 0;
      _nc_top_panel = pan;

      err = OK;

      dStack("<lt%d>", 9, pan);
    }
  returnCode(err);
}
Exemplo n.º 9
0
move_panel(PANEL * pan, int starty, int startx)
{
  int rc = ERR;

  T((T_CALLED("move_panel(%p,%d,%d)"), (void *)pan, starty, startx));

  if (pan)
    {
      GetHook(pan);
      if (IS_LINKED(pan))
	{
	  Touchpan(pan);
	  PANEL_UPDATE(pan, (PANEL *) 0);
	}
      rc = mvwin(pan->win, starty, startx);
    }
  returnCode(rc);
}
Exemplo n.º 10
0
del_panel(PANEL * pan)
{
  int err = OK;

  T((T_CALLED("del_panel(%p)"), (void *)pan));
  if (pan)
    {
      dBug(("--> del_panel %s", USER_PTR(pan->user)));
      {
	GetHook(pan);
	HIDE_PANEL(pan, err, OK);
	free((void *)pan);
      }
    }
  else
    err = ERR;

  returnCode(err);
}
Exemplo n.º 11
0
hide_panel(register PANEL * pan)
{
  int err = ERR;

  T((T_CALLED("hide_panel(%p)"), (void *)pan));

  if (pan)
    {
      GetHook(pan);

      dBug(("--> hide_panel %s", USER_PTR(pan->user)));
      dStack("<u%d>", 1, pan);

      HIDE_PANEL(pan, err, ERR);

      err = OK;

      dStack("<u%d>", 9, pan);
    }
  returnCode(err);
}
Exemplo n.º 12
0
panel_below(const PANEL * pan)
{
  PANEL *result;

  T((T_CALLED("panel_below(%p)"), (const void *)pan));
  if (pan)
    {
      GetHook(pan);
      /* we must not return the pseudo panel */
      result = Is_Pseudo(pan->below) ? (PANEL *) 0 : pan->below;
    }
  else
    {
#if NCURSES_SP_FUNCS
      result = ceiling_panel(CURRENT_SCREEN);
#else
      /* if top and bottom are equal, we have no or only the pseudo panel */
      result = EMPTY_STACK()? (PANEL *) 0 : _nc_top_panel;
#endif
    }
  returnPanel(result);
}
Exemplo n.º 13
0
      default:

         HError(2319,"HERest: Unknown switch %s",s);

      }

   } 

   if (NextArg() != STRINGARG)

      HError(2319,"HERest: file name of vocabulary list expected");



   Initialise(fbInfo, &fbInfoStack, &hset, GetStrArg());

   InitUttInfo(utt, twoDataFiles);

   numUtt = 1;



   if (trace&T_TOP) 

      SetTraceFB(); /* allows HFB to do top-level tracing */



   do {

      if (NextArg()!=STRINGARG)

         HError(2319,"HERest: data file name expected");

      if (twoDataFiles && (parMode!=0)){

         if ((NumArgs() % 2) != 0)
Exemplo n.º 14
0
         hmmExt = GetStrArg(); break;

      case 'B':

         saveBinary=TRUE;

         break;

      case 'F':

         if (NextArg() != STRINGARG)

            HError(2319,"HERest: Data File format expected");

         if((dff = Str2Format(GetStrArg())) == ALIEN)

            HError(-2389,"HERest: Warning ALIEN Data file format set");

         break;

      case 'G':
Exemplo n.º 15
0
/* UpdateTrans: use acc values to calc new estimate for transP */
void UpdateTrans(HLink hmm)
{
   int i,j,N;
   float x,occi;
   TrAcc *ta;
   MLink q;

   q=FindMacroStruct(&hset,'h',hmm);
   ta = (TrAcc *) GetHook(hmm->transP);
   if (ta==NULL) return;   /* already done */
   N = hmm->numStates;
   for (i=1;i<N;i++) {
      occi = ta->occ[i];
      if (occi > 0.0) 
         for (j=2;j<=N;j++) {
            x = ta->tran[i][j]/occi;
            hmm->transP[i][j] = (x>MINLARG)?log(x):LZERO;
         }
      else
         HError(-2424,"UpdateTrans: Model [%s]: no transitions out of state %d",q->id->name,i);
   }
   SetHook(hmm->transP,NULL);
}
Exemplo n.º 16
0
/* UpdateCounts: using frames in seg i and alignment in states/mixes */
void UpdateCounts(int segNum, int segLen, IntVec states,IntVec *mixes)
{
   int M=0,i,j,k,s,m,state,last;
   StreamElem *ste;
   MixPDF *mp = NULL;
   WtAcc *wa;
   MuAcc *ma;
   VaAcc *va;
   TrAcc *ta;
   Vector v;
   Observation obs;
   TMixRec *tmRec = NULL;
   float x,y;

   last = 1;  /* last before 1st emitting state must be 1 */
   ta = (TrAcc *)GetHook(hmmLink->transP); 
   for (i=1; i<=segLen; i++){
      state = states[i];
      if (trace&T_CNT)
         printf("  Seg %d -> state %d\n",i,state);
      if (uFlags&(UPMEANS|UPVARS|UPMIXES)){
         obs = GetSegObs(segStore, segNum, i);
         if (hset.hsKind == TIEDHS)
            PrecomputeTMix(&hset, &obs, 50.0, 0);         
         ste = hmmLink->svec[state].info->pdf+1;
         for (s=1; s<=nStreams; s++,ste++){
            if (hset.hsKind==DISCRETEHS){
               m = obs.vq[s]; v = NULL;
            } else {
               v = obs.fv[s]; m = mixes[s][i];
            }
            switch(hset.hsKind){
            case TIEDHS:
               tmRec = &(hset.tmRecs[s]);
               M = tmRec->nMix;
               break;
            case PLAINHS:
            case SHAREDHS:
            case DISCRETEHS:
               M = ste->nMix;
               break;
            }
            if (m<1 || m > M)
               HError(2170,"UpdateCounts: mix/vq idx out of range[%d]",m);
            if (trace&T_CNT)
               printf("   stream %d -> mix %d[%d]\n",s,m,M); 
            /* update mixture weight */
            if (M>1 && (uFlags&UPMIXES)) {
               wa = (WtAcc *)ste->hook;
               wa->occ += 1.0; wa->c[m] += 1.0;
               if (trace&T_CNT)
                  printf("   mix wt -> %.1f\n",wa->c[m]);
            }
            if (hset.hsKind==DISCRETEHS) continue;
            
            /* update state/mixture component */
            switch(hset.hsKind){
            case PLAINHS:
            case SHAREDHS:
               mp = ste->spdf.cpdf[m].mpdf;
               break;
            case TIEDHS:
               mp = tmRec->mixes[m];
               break;
            }
            ma = (MuAcc *)GetHook(mp->mean);
            va = (VaAcc *)GetHook(mp->cov.var);
            ma->occ += 1.0; va->occ += 1.0;
            for (j=1; j<=hset.swidth[s]; j++) {
               x = v[j] - mp->mean[j];
               ma->mu[j] += x;
               if (uFlags&UPVARS)
                  switch(mp->ckind){
                  case DIAGC: 
                     va->cov.var[j] += x*x;
                     break;
                  case FULLC:
                     for (k=1; k<=j; k++){
                        y = v[k]-mp->mean[k];
                        va->cov.inv[j][k] += x*y;
                     }
                     break;
                  default:
                     HError(2124,"UpdateCounts: bad cov kind %d\n",
                            mp->ckind);
                  }                 
            }
            if (trace&T_CNT) {
               ShowVector("   mean ->",ma->mu,6);
               if (uFlags&UPVARS) {
                  if (mp->ckind==DIAGC)
                     ShowVector("   var ->",va->cov.var,6);
                  else
                     ShowTriMat("   cov ->",va->cov.inv,6,6);
               }
               fflush(stdout);
            }
         }
      }
      /* update transition probs */
      if (uFlags&UPTRANS){
         ta->occ[last] += 1.0;
         ta->tran[last][state] += 1.0;
         last = state;
         if (i==segLen){  /* remember final state */
            ta->occ[state] += 1.0;
            ta->tran[state][nStates] += 1.0;
         }
         if (trace&T_CNT) {
            ShowMatrix("   tran ->",ta->tran,6,6);
            fflush(stdout);
         }
      }
   }
}
Exemplo n.º 17
0
/* UpdateVars: use acc values to calc new estimate of variances */
static void UpdateVars(HMMSet *hset, int px, HLink hmm)
{
   int i,s,m,k,M,N,vSize;
   float occim,x,muDiffk,dmu;
   Vector minV;
   VaAcc *va;
   MuAcc *ma;
   StateElem *se;
   StreamElem *ste;
   MixtureElem *me;
   Vector mean,var;
   Covariance cov;
   Boolean mixFloored,shared;
   
   N = hmm->numStates;
   se = hmm->svec+2; 
   for (i=2; i<N; i++,se++){
      ste = se->info->pdf+1;
      for (s=1;s<=S;s++,ste++){
         minV = vFloor[s];
         me = ste->info->spdf.cpdf + 1; 
         M = ste->info->nMix;
         for (m=1;m<=M;m++,me++)
	   if (MixWeight(hset,me->weight) > MINMIX){
               cov = me->mpdf->cov;
               va = GetHook(cov.var);
               mean = me->mpdf->mean;
               vSize = VectorSize(mean);
               ma = GetHook(mean);
               if (va != NULL){
                  occim = va->occ;
                  mixFloored = FALSE;
                  if (occim > 0.0){
                     shared = (GetUse(cov.var)>1 || ma==NULL || ma->occ<=0.0) ? TRUE : FALSE;
                     if (me->mpdf->ckind==DIAGC) {
		         var = cov.var;
			 for (k=1; k<=vSize; k++){
			   if (shared) muDiffk = 0.0;
			   else {
			     dmu = (ma->mu[k])/(mapTau+occim);
			     muDiffk = 2*dmu*ma->mu[k] - dmu*dmu*occim;
			   }
                           x = (mapTau*var[k]  + va->cov.var[k] - muDiffk) / (mapTau + occim);
                           if (applyVFloor && x<minV[k]) {
                             x = minV[k];
                              nFloorVar++;
                              mixFloored = TRUE;
			    }
			   cov.var[k] = x;
			 }
       		     }
                     else { /* FULLC */
		       HError(999,"MAP estimation of full covariance matrices not supported");
		     }
		  }
                  if (mixFloored == TRUE) nFloorVarMix++;
		  SetHook(cov.var,NULL);
               }
            }
      }
   }
}
Exemplo n.º 18
0
         /* track speakers */	 

         if (UpdateSpkrStats(&hset,&xfInfo, datafn)) spUtt=0;

	 /* Check to see whether set-up is valid */

	 CheckUpdateSetUp();

         fbInfo->inXForm = xfInfo.inXForm;

         fbInfo->al_inXForm = xfInfo.al_inXForm;

         fbInfo->paXForm = xfInfo.paXForm;

         if ((maxSpUtt==0) || (spUtt<maxSpUtt))

            DoForwardBackward(fbInfo, utt, datafn, datafn2) ;

         numUtt += 1; spUtt++;

      }

   } while (NumArgs()>0);



   if (uFlags&UPXFORM) {/* ensure final speaker correctly handled */ 

      UpdateSpkrStats(&hset,&xfInfo, NULL); 

      if (trace&T_TOP) {

         printf("Reestimation complete - average log prob per frame = %e (%d frames)\n",

                totalPr/totalT, totalT);

      }

   } else {

      if (parMode>0  || (parMode==0 && (updateMode&UPMODE_DUMP))){

         MakeFN("HER$.acc",newDir,NULL,newFn);

         f=DumpAccs(&hset,newFn,uFlags,parMode);

         tmpFlt = (float)totalPr;

         WriteFloat(f,&tmpFlt,1,ldBinary);

         WriteInt(f,(int*)&totalT,1,ldBinary);

         fclose( f );

      }

      if (parMode <= 0) {

         if (stats) {

            StatReport(&hset);

         }

         if (updateMode&UPMODE_UPDATE)

            UpdateModels(&hset,utt->pbuf2);

      }

   }

   ResetHeap(&uttStack);

   ResetHeap(&fbInfoStack);

   ResetHeap(&hmmStack);