Add beta support for binding bungee to unix socket addresses
This commit is contained in:
@@ -43,5 +43,11 @@
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-transport-native-unix-common</artifactId>
|
||||
<version>${netty.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@@ -2,7 +2,9 @@ package net.md_5.bungee;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.primitives.UnsignedLongs;
|
||||
import io.netty.channel.unix.DomainSocketAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.UUID;
|
||||
@@ -21,15 +23,30 @@ public class Util
|
||||
* @param hostline in the format of 'host:port'
|
||||
* @return the constructed hostname + port.
|
||||
*/
|
||||
public static InetSocketAddress getAddr(String hostline)
|
||||
public static SocketAddress getAddr(String hostline)
|
||||
{
|
||||
URI uri;
|
||||
URI uri = null;
|
||||
try
|
||||
{
|
||||
uri = new URI( "tcp://" + hostline );
|
||||
uri = new URI( hostline );
|
||||
} catch ( URISyntaxException ex )
|
||||
{
|
||||
throw new IllegalArgumentException( "Bad hostline: " + hostline, ex );
|
||||
}
|
||||
|
||||
if ( uri != null && "unix".equals( uri.getScheme() ) )
|
||||
{
|
||||
return new DomainSocketAddress( uri.getPath() );
|
||||
}
|
||||
|
||||
if ( uri == null || uri.getHost() == null )
|
||||
{
|
||||
try
|
||||
{
|
||||
uri = new URI( "tcp://" + hostline );
|
||||
} catch ( URISyntaxException ex )
|
||||
{
|
||||
throw new IllegalArgumentException( "Bad hostline: " + hostline, ex );
|
||||
}
|
||||
}
|
||||
|
||||
if ( uri.getHost() == null )
|
||||
|
@@ -3,6 +3,7 @@ package net.md_5.bungee.api;
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.io.File;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@@ -206,6 +207,18 @@ public abstract class ProxyServer
|
||||
*/
|
||||
public abstract ServerInfo constructServerInfo(String name, InetSocketAddress address, String motd, boolean restricted);
|
||||
|
||||
/**
|
||||
* Factory method to construct an implementation specific server info
|
||||
* instance.
|
||||
*
|
||||
* @param name name of the server
|
||||
* @param address connectable Minecraft address + port of the server
|
||||
* @param motd the motd when used as a forced server
|
||||
* @param restricted whether the server info restricted property will be set
|
||||
* @return the constructed instance
|
||||
*/
|
||||
public abstract ServerInfo constructServerInfo(String name, SocketAddress address, String motd, boolean restricted);
|
||||
|
||||
/**
|
||||
* Returns the console overlord for this proxy. Being the console, this
|
||||
* command server cannot have permissions or groups, and will be able to
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package net.md_5.bungee.api.config;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -18,7 +19,7 @@ public class ListenerInfo
|
||||
/**
|
||||
* Host to bind to.
|
||||
*/
|
||||
private final InetSocketAddress host;
|
||||
private final SocketAddress socketAddress;
|
||||
/**
|
||||
* Displayed MOTD.
|
||||
*/
|
||||
@@ -102,4 +103,16 @@ public class ListenerInfo
|
||||
{
|
||||
return ( serverPriority.size() > 1 ) ? serverPriority.get( 1 ) : getDefaultServer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the bind address as an InetSocketAddress if possible.
|
||||
*
|
||||
* @return bind host
|
||||
* @deprecated BungeeCord can listen via Unix domain sockets
|
||||
*/
|
||||
@Deprecated
|
||||
public InetSocketAddress getHost()
|
||||
{
|
||||
return (InetSocketAddress) socketAddress;
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package net.md_5.bungee.api.config;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.Collection;
|
||||
import net.md_5.bungee.api.Callback;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
@@ -26,9 +27,20 @@ public interface ServerInfo
|
||||
* class.
|
||||
*
|
||||
* @return the IP and port pair for this server
|
||||
* @deprecated BungeeCord can connect via Unix domain sockets
|
||||
*/
|
||||
@Deprecated
|
||||
InetSocketAddress getAddress();
|
||||
|
||||
/**
|
||||
* Gets the connectable address this server. Implementations
|
||||
* expect this to be used as the unique identifier per each instance of this
|
||||
* class.
|
||||
*
|
||||
* @return the address for this server
|
||||
*/
|
||||
SocketAddress getSocketAddress();
|
||||
|
||||
/**
|
||||
* Get the set of all players on this server.
|
||||
*
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package net.md_5.bungee.api.connection;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
|
||||
@@ -16,9 +17,18 @@ public interface Connection
|
||||
* Gets the remote address of this connection.
|
||||
*
|
||||
* @return the remote address
|
||||
* @deprecated BungeeCord can accept connections via Unix domain sockets
|
||||
*/
|
||||
@Deprecated
|
||||
InetSocketAddress getAddress();
|
||||
|
||||
/**
|
||||
* Gets the remote address of this connection.
|
||||
*
|
||||
* @return the remote address
|
||||
*/
|
||||
SocketAddress getSocketAddress();
|
||||
|
||||
/**
|
||||
* Disconnects this end of the connection for the specified reason. If this
|
||||
* is an {@link ProxiedPlayer} the respective server connection will be
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package net.md_5.bungee.api;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.Collection;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
@@ -19,6 +20,12 @@ public class ServerConnectRequestTest
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocketAddress getSocketAddress()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getAddress()
|
||||
{
|
||||
|
@@ -1,6 +1,8 @@
|
||||
package net.md_5.bungee.util;
|
||||
|
||||
import io.netty.channel.unix.DomainSocketAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -44,6 +46,9 @@ public class AddressParseTest
|
||||
},
|
||||
{
|
||||
"[0:0:0:0:0:0:0:1]:1337", "0:0:0:0:0:0:0:1", 1337
|
||||
},
|
||||
{
|
||||
"unix:///var/run/bungee.sock", "/var/run/bungee.sock", -1
|
||||
}
|
||||
} );
|
||||
}
|
||||
@@ -54,8 +59,23 @@ public class AddressParseTest
|
||||
@Test
|
||||
public void test()
|
||||
{
|
||||
InetSocketAddress parsed = Util.getAddr( line );
|
||||
Assert.assertEquals( host, parsed.getHostString() );
|
||||
Assert.assertEquals( port, parsed.getPort() );
|
||||
SocketAddress parsed = Util.getAddr( line );
|
||||
|
||||
if ( parsed instanceof InetSocketAddress )
|
||||
{
|
||||
InetSocketAddress tcp = (InetSocketAddress) parsed;
|
||||
|
||||
Assert.assertEquals( host, tcp.getHostString() );
|
||||
Assert.assertEquals( port, tcp.getPort() );
|
||||
} else if ( parsed instanceof DomainSocketAddress )
|
||||
{
|
||||
DomainSocketAddress unix = (DomainSocketAddress) parsed;
|
||||
|
||||
Assert.assertEquals( host, unix.path() );
|
||||
Assert.assertEquals( -1, port );
|
||||
} else
|
||||
{
|
||||
throw new AssertionError( "Unknown socket " + parsed );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user