Changeset 8744c83f


Ignore:
Timestamp:
Nov 27, 2011 7:05:38 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
1339209f
Parents:
09731ff
Message:

optimize outbound whitelist

File:
1 edited

Legend:

Unmodified
Added
Removed
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/irc/IRCFilter.java

    r09731ff r8744c83f  
    11package net.i2p.i2ptunnel.irc;
     2
     3import java.util.Arrays;
     4import java.util.HashSet;
     5import java.util.Set;
    26
    37import net.i2p.data.DataHelper;
     
    140144    }
    141145   
    142     /*************************************************************************
    143      *
    144      *  Modify or filter a single outbound line.
    145      *
    146      *  @param helper may be null
    147      *  @return the original or modified line, or null if it should be dropped.
    148      */
    149     public static String outboundFilter(String s, StringBuffer expectedPong, DCCHelper helper) {
    150 
    151         String field[]=s.split(" ",3);
    152         String command;
     146    private static final Set<String> _allowedOutbound;
     147    static {
    153148        final String[] allowedCommands =
    154149        {
     
    193188                "CAP"
    194189        };
     190        _allowedOutbound = new HashSet(64);
     191        _allowedOutbound.addAll(Arrays.asList(allowedCommands));
     192    }
     193
     194    /*************************************************************************
     195     *
     196     *  Modify or filter a single outbound line.
     197     *
     198     *  @param helper may be null
     199     *  @return the original or modified line, or null if it should be dropped.
     200     */
     201    public static String outboundFilter(String s, StringBuffer expectedPong, DCCHelper helper) {
     202
     203        String field[]=s.split(" ",3);
    195204
    196205        if(field[0].length()==0)
     
    201210            return null; // wtf
    202211       
    203         command = field[0].toUpperCase();
     212        String command = field[0].toUpperCase();
    204213
    205214        if ("PING".equals(command)) {
     
    243252
    244253        // Allow all allowedCommands
    245         for(int i=0;i<allowedCommands.length;i++)
    246         {
    247             if(allowedCommands[i].equals(command))
    248                 return s;
    249         }
     254        if (_allowedOutbound.contains(command))
     255            return s;
    250256       
    251257        // mIRC sends "NOTICE user :DCC Send file (IP)"
Note: See TracChangeset for help on using the changeset viewer.