Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
Openfire
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Openfire
Commits
e8cc92f4
Commit
e8cc92f4
authored
Aug 16, 2016
by
Dave Cridland
Committed by
GitHub
Aug 16, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #628 from guusdk/OF-1170_proxy_addresses
OF-1170 Advertise all proxy addresses
parents
1d859149
352043f7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
31 deletions
+76
-31
FileTransferProxy.java
...ftware/openfire/filetransfer/proxy/FileTransferProxy.java
+76
-31
No files found.
src/java/org/jivesoftware/openfire/filetransfer/proxy/FileTransferProxy.java
View file @
e8cc92f4
...
...
@@ -21,12 +21,10 @@
package
org
.
jivesoftware
.
openfire
.
filetransfer
.
proxy
;
import
java.net.InetAddress
;
import
java.net.NetworkInterface
;
import
java.net.SocketException
;
import
java.net.UnknownHostException
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Iterator
;
import
java.util.Map
;
import
java.util.*
;
import
org.dom4j.DocumentHelper
;
import
org.dom4j.Element
;
...
...
@@ -94,9 +92,9 @@ public class FileTransferProxy extends BasicModule
private
IQHandlerInfo
info
;
private
RoutingTable
routingTable
;
private
PacketRouter
router
;
private
String
proxyIP
;
private
ProxyConnectionManager
connectionManager
;
// The address to operate on. Null for any address.
private
InetAddress
bindInterface
;
...
...
@@ -136,14 +134,17 @@ public class FileTransferProxy extends BasicModule
IQ
reply
=
IQ
.
createResultIQ
(
packet
);
Element
newChild
=
reply
.
setChildElement
(
"query"
,
FileTransferManager
.
NAMESPACE_BYTESTREAMS
);
Element
response
=
newChild
.
addElement
(
"streamhost"
);
response
.
addAttribute
(
"jid"
,
getServiceDomain
());
response
.
addAttribute
(
"host"
,
proxyIP
);
response
.
addAttribute
(
"port"
,
String
.
valueOf
(
connectionManager
.
getProxyPort
()));
for
(
InetAddress
address
:
getAddresses
()
)
{
Element
response
=
newChild
.
addElement
(
"streamhost"
);
response
.
addAttribute
(
"jid"
,
getServiceDomain
()
);
response
.
addAttribute
(
"host"
,
address
.
getHostAddress
()
);
response
.
addAttribute
(
"port"
,
String
.
valueOf
(
connectionManager
.
getProxyPort
()
)
);
}
router
.
route
(
reply
);
return
true
;
}
else
if
(
packet
.
getType
()
==
IQ
.
Type
.
set
&&
childElement
!=
null
)
{
else
if
(
packet
.
getType
()
==
IQ
.
Type
.
set
)
{
String
sid
=
childElement
.
attributeValue
(
"sid"
);
JID
from
=
packet
.
getFrom
();
JID
to
=
new
JID
(
childElement
.
elementTextTrim
(
"activate"
));
...
...
@@ -170,39 +171,83 @@ public class FileTransferProxy extends BasicModule
}
@Override
public
void
initialize
(
XMPPServer
server
)
{
public
void
initialize
(
XMPPServer
server
)
{
super
.
initialize
(
server
);
proxyServiceName
=
JiveGlobals
.
getProperty
(
"xmpp.proxy.service"
,
"proxy"
);
routingTable
=
server
.
getRoutingTable
();
router
=
server
.
getPacketRouter
();
// Load the external IP and port information
String
interfaceName
=
JiveGlobals
.
getXMLProperty
(
"network.interface"
);
bindInterface
=
null
;
if
(
interfaceName
!=
null
)
{
if
(
interfaceName
.
trim
().
length
()
>
0
)
{
try
{
bindInterface
=
InetAddress
.
getByName
(
interfaceName
);
}
catch
(
UnknownHostException
e
)
{
Log
.
error
(
"Error binding to network.interface"
,
e
);
}
final
String
hardCodedProxyIP
=
JiveGlobals
.
getProperty
(
"xmpp.proxy.externalip"
);
final
String
interfaceName
=
JiveGlobals
.
getXMLProperty
(
"network.interface"
);
if
(
hardCodedProxyIP
!=
null
&&
!
hardCodedProxyIP
.
trim
().
isEmpty
()
)
{
// First choice: a hardcoded IP address, if one exists.
try
{
bindInterface
=
InetAddress
.
getByName
(
hardCodedProxyIP
.
trim
()
);
}
catch
(
UnknownHostException
e
)
{
Log
.
error
(
"Error binding to xmpp.proxy.externalip '{}'"
,
interfaceName
,
e
);
}
}
try
{
proxyIP
=
JiveGlobals
.
getProperty
(
"xmpp.proxy.externalip"
,
(
bindInterface
!=
null
?
bindInterface
.
getHostAddress
()
:
InetAddress
.
getLocalHost
().
getHostAddress
()));
else
if
(
interfaceName
!=
null
&&
!
interfaceName
.
trim
().
isEmpty
()
)
{
// No hardcoded IP? Let's see if we hardcoded a specific interface, then use its address.
try
{
bindInterface
=
InetAddress
.
getByName
(
interfaceName
.
trim
()
);
}
catch
(
UnknownHostException
e
)
{
Log
.
error
(
"Error binding to network.interface '{}'"
,
interfaceName
,
e
);
}
}
catch
(
UnknownHostException
e
)
{
Log
.
error
(
"Couldn't discover local host"
,
e
);
else
{
// If no configuration is available, use all available addresses.
bindInterface
=
null
;
}
connectionManager
=
new
ProxyConnectionManager
(
getFileTransferManager
(
server
));
}
/**
* Returns the IP address(es) that are used.
*/
private
Set
<
InetAddress
>
getAddresses
()
{
final
Set
<
InetAddress
>
result
=
new
HashSet
<>();
if
(
bindInterface
!=
null
)
{
result
.
add
(
bindInterface
);
}
else
{
// When there's no specific address configured, return all available addresses.
try
{
final
Enumeration
<
NetworkInterface
>
networkInterfaces
=
NetworkInterface
.
getNetworkInterfaces
();
while
(
networkInterfaces
.
hasMoreElements
()
)
{
final
NetworkInterface
networkInterface
=
networkInterfaces
.
nextElement
();
final
Enumeration
<
InetAddress
>
inetAddresses
=
networkInterface
.
getInetAddresses
();
while
(
inetAddresses
.
hasMoreElements
()
)
{
result
.
add
(
inetAddresses
.
nextElement
()
);
}
}
}
catch
(
SocketException
e
)
{
Log
.
error
(
"Error determining all addresses for this server"
,
e
);
}
}
return
result
;
}
private
FileTransferManager
getFileTransferManager
(
XMPPServer
server
)
{
return
server
.
getFileTransferManager
();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment