/// <summary> /// 黑名單分數是否到期 /// </summary> /// <param name="blockHole">黑名單資訊</param> /// <returns></returns> private bool IsExpired(BlockHole blockHole) { if (blockHole.ABUSE_SCORE == null) { return(true); } var leadtime = new TimeSpan(_monitor.RECEIVE_TIME.Value.Ticks - blockHole.REQUEST_TIME.Value.Ticks).Hours; return(leadtime >= _setting.CHECK_CYCLE); }
//HS D private BlockHole ParseBlockHole(TokenSet followers){ Debug.Assert(this.currentToken == Token.Hole); Hashtable templateParams = new Hashtable(); this.GetNextToken(); this.Skip(Token.LeftBrace); if (this.currentToken != Token.RightBrace){ string templateParam = this.scanner.GetTokenSource(); this.GetNextToken(); this.Skip(Token.Colon); Expression templateParamVal = this.currentToken == Token.IntegerLiteral ? this.ParseIntegerLiteral() : (this.currentToken == Token.RealLiteral ? this.ParseRealLiteral() : this.ParseCommaSeparetedIdentifierSet()); templateParams[templateParam] = templateParamVal; while (this.currentToken == Token.Comma){ this.GetNextToken(); templateParam = this.scanner.GetTokenSource(); this.GetNextToken(); this.Skip(Token.Colon); templateParamVal = this.currentToken == Token.IntegerLiteral ? this.ParseIntegerLiteral() : (this.currentToken == Token.RealLiteral ? this.ParseRealLiteral() : this.ParseCommaSeparetedIdentifierSet()); templateParams[templateParam] = templateParamVal; } } this.Skip(Token.RightBrace); Literal one = new Literal(1); ConstructArray empty = new ConstructArray(); Literal repeat = templateParams.ContainsKey("repeat") ? (Literal) templateParams["repeat"] : one; Literal ifbranches = templateParams.ContainsKey("ifbranches") ? (Literal) templateParams["ifbranches"] : one; Literal branchops = templateParams.ContainsKey("branchops") ? (Literal) templateParams["branchops"] : one; Literal conjunctions = templateParams.ContainsKey("conjunctions") ? (Literal) templateParams["conjunctions"] : one; ConstructArray ops = templateParams.ContainsKey("ops") ? (ConstructArray) templateParams["ops"] : empty; ConstructArray condvars = templateParams.ContainsKey("condvars") ? (ConstructArray) templateParams["condvars"] : empty; ConstructArray argvars = templateParams.ContainsKey("argvars") ? (ConstructArray) templateParams["argvars"] : empty; SourceContext sctx = this.scanner.CurrentSourceContext; BlockHole result = new BlockHole(sctx, repeat, ifbranches, branchops, conjunctions, ops, condvars, argvars); //, this.currMethod, opMethods); result.SourceContext = sctx; //HS D: HACK FIXME DefineBlockHoleMethod(this.currentTypeNode); return result; }
//HS D //FIXME: move! public virtual Statement VisitBlockHole(BlockHole block){ if (block == null) return null; SourceContext sctx = block.SourceContext; ExpressionList args = new ExpressionList(); args.Add(block.Repeat); args.Add(block.IfBranches); args.Add(block.BranchOps); args.Add(block.Conjunctions); args.Add(block.Ops); args.Add(block.CondVars); args.Add(block.ArgVars); Expression tgt = new Identifier("BlockHole", sctx); MethodCall c = new MethodCall(tgt, args); return new ExpressionStatement(c); /* //HACK FIXME... int repeatN = (int) block.Repeat.Value; object ifBranchesOrig = block.IfBranches.Value; bool ifBranchesNoElse = !(ifBranchesOrig is int); int ifBranches = ifBranchesNoElse ? (int) ((double) ifBranchesOrig) : (int) ifBranchesOrig; int branchOps = (int) block.BranchOps.Value; int conjunctions = (int) block.Conjunctions.Value; ExpressionList ops = block.Ops.Initializers; ExpressionList condVars = block.CondVars.Initializers; ExpressionList argVars = block.ArgVars.Initializers; SourceContext sctx = block.SourceContext; Method declaringMethod = block.DeclaringMethod; Hashtable classOpMethods = block.ClassOpMethods; ParameterList callingMtdParams = declaringMethod.Parameters; Identifier opN = (Identifier) ((Literal) ops[0]).Value; //FIXME: Method op = (Method) classOpMethods[opN.Name]; //HACK FIXME Debug.Assert (op != null, "Did you forget to mark method " + opN.Name + " as operation?"); //FIXME //op.IsOperation bool isVoid = IsVoidType(op.ReturnType); Expression tgt = new MemberBinding(null, op); //op.Name; ParameterList ps = op.Parameters; bool opTr = op.IsTransformable; bool[] trPrms = new bool[ps.Count]; for (int i = 0; i < ps.Count; i++) { Parameter p = ps[i]; trPrms[i] = (p.Flags & ParameterFlags.Transformable) > 0; } StatementList stmts = new StatementList(); for(int i = 1; i <= repeatN; i++) stmts.Add(GenIfBranch(sctx, ifBranches, ifBranchesNoElse, conjunctions, tgt, condVars, argVars, ps, isVoid, opTr, trPrms, callingMtdParams)); Block res = new Block(stmts); Console.WriteLine("HS D - block hole...\n"); PrintMe(0, res); return res; */ }