Source Code Cross Referenced for Connection.java in  » Chat » freecs » freecs » content » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Chat » freecs » freecs.content 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright (C) 2003  Manfred Andres
003:         * 
004:         * This program is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU General Public License
006:         * as published by the Free Software Foundation; either version 2
007:         * of the License, or (at your option) any later version.
008:         * 
009:         * This program is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012:         * GNU General Public License for more details.
013:         * 
014:         * You should have received a copy of the GNU General Public License
015:         * along with this program; if not, write to the Free Software
016:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
017:         */
018:
019:        /**
020:         * The Connection-class is used to store connection-specific data
021:         * only once. 
022:         */package freecs.content;
023:
024:        import freecs.Server;
025:        import java.net.InetAddress;
026:        import java.net.UnknownHostException;
027:        import java.nio.channels.SocketChannel;
028:        import java.nio.channels.SelectionKey;
029:
030:        public class Connection {
031:            // this is the remote-address of the socket-connection
032:            public InetAddress peerAddress = null;
033:            public String peerIp = null;
034:
035:            // this represents the real-client-ip if it has been identified
036:            public String clientIp = null;
037:            public InetAddress clientAddress = null;
038:
039:            // this is the proxy forward-chain (from the xForwardedFor headerfield)
040:            public String[] fwChain = null;
041:
042:            // true if the client has a direct-socket-connectino
043:            public boolean isDirectlyConnected = false;
044:
045:            public Connection(SelectionKey sk) {
046:                peerAddress = ((SocketChannel) sk.channel()).socket()
047:                        .getInetAddress();
048:                peerIp = peerAddress.getHostAddress();
049:                clientAddress = null;
050:                clientIp = null;
051:                if (Server.TRACE_CREATE_AND_FINALIZE)
052:                    Server.log(this ,
053:                            "++++++++++++++++++++++++++++++++++++++++CREATE",
054:                            Server.MSG_STATE, Server.LVL_VERY_VERBOSE);
055:            }
056:
057:            public Connection(SelectionKey sk, String[] fwChain, boolean idc) {
058:                isDirectlyConnected = idc;
059:                peerAddress = ((SocketChannel) sk.channel()).socket()
060:                        .getInetAddress();
061:                if (peerAddress != null)
062:                    peerIp = peerAddress.getHostAddress();
063:                if (fwChain != null) {
064:                    isDirectlyConnected = false;
065:                    this .fwChain = fwChain;
066:                    if (fwChain[0].indexOf(".") > -1)
067:                        try {
068:                            clientAddress = InetAddress.getByName(fwChain[0]);
069:                            if (clientAddress != null)
070:                                clientIp = clientAddress.getHostAddress();
071:                        } catch (UnknownHostException uhe) {
072:                            Server.debug(this ,
073:                                    "Unable to determine real IP for "
074:                                            + fwChain[0], uhe,
075:                                    Server.MSG_STATE, Server.LVL_MINOR);
076:                        }
077:                    return;
078:                } else if (!idc) {
079:                    return;
080:                }
081:                clientAddress = peerAddress;
082:                if (peerAddress != null)
083:                    clientIp = clientAddress.getHostAddress();
084:                if (Server.TRACE_CREATE_AND_FINALIZE)
085:                    Server.log(this ,
086:                            "++++++++++++++++++++++++++++++++++++++++CREATE",
087:                            Server.MSG_STATE, Server.LVL_VERY_VERBOSE);
088:            }
089:
090:            private volatile String toStringVal = null;
091:
092:            public String toString() {
093:                if (toStringVal == null) {
094:                    StringBuffer sb = new StringBuffer();
095:                    if (!isDirectlyConnected)
096:                        sb.append("proxy=");
097:                    sb.append(peerIp);
098:                    if (!isDirectlyConnected && clientIp != null) {
099:                        sb.append(" clientIp=");
100:                        sb.append(clientIp);
101:                    }
102:                    toStringVal = sb.toString();
103:                }
104:                return toStringVal;
105:            }
106:
107:            public boolean isBanable() {
108:                if (this .clientIp != null)
109:                    return true;
110:                if (fwChain != null && fwChain.length > 0 && fwChain[0] != null
111:                        && fwChain[0].length() > 0)
112:                    return true;
113:                return false;
114:            }
115:
116:            public boolean equals(Object o) {
117:                if (o == null)
118:                    return false;
119:                if (!(o instanceof  Connection))
120:                    return false;
121:                Connection c = (Connection) o;
122:                if (this .clientIp == null && c.clientIp != null)
123:                    return false;
124:                if (this .clientIp != null && !this .clientIp.equals(c.clientIp))
125:                    return false;
126:                if (this .peerIp == null && c.peerIp != null)
127:                    return false;
128:                if (this .peerIp != null && !this .peerIp.equals(c.peerIp))
129:                    return false;
130:                if (this .fwChain == null && c.fwChain != null)
131:                    return false;
132:                if (this .fwChain != null && !this .fwChain.equals(c.fwChain))
133:                    return false;
134:                return true;
135:            }
136:
137:            public int hashCode() {
138:                if (this .clientIp != null && this .peerIp != null) {
139:                    return (this .clientIp + "/" + this .peerIp).hashCode();
140:                } else if (this .peerIp != null) {
141:                    return this .peerIp.hashCode();
142:                } else {
143:                    return this .clientIp.hashCode();
144:                }
145:            }
146:
147:            public String getBanKey() {
148:                if (this .clientIp != null)
149:                    return this .clientIp;
150:                if (this .fwChain != null && fwChain.length > 0) {
151:                    StringBuffer sb = new StringBuffer();
152:                    sb.append(this .peerIp);
153:                    sb.append(":").append(fwChain[fwChain.length - 1]);
154:                    return sb.toString();
155:                }
156:                return null;
157:            }
158:
159:            public void finalize() {
160:                if (Server.TRACE_CREATE_AND_FINALIZE)
161:                    Server
162:                            .log(
163:                                    this ,
164:                                    "----------------------------------------FINALIZED",
165:                                    Server.MSG_STATE, Server.LVL_VERY_VERBOSE);
166:            }
167:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.