populateTransportSettings method
Populates the stream settings based on transport parameters.
transport
specifies the transport protocol (e.g., 'tcp', 'ws').
headerType
is the header type for the transport.
host
is the host for the connection.
path
is the path for the connection.
seed
is the seed for kcp transport.
quicSecurity
is the security for quic transport.
key
is the key for quic transport.
mode
is the mode for grpc transport.
serviceName
is the service name for grpc transport.
Returns the server name indicator (SNI) if available.
Implementation
String populateTransportSettings({
required String transport,
required String? headerType,
required String? host,
required String? path,
required String? seed,
required String? quicSecurity,
required String? key,
required String? mode,
required String? serviceName,
}) {
var sni = '';
streamSetting['network'] = transport;
if (transport == 'tcp') {
streamSetting['tcpSettings'] = {
'header': <String, dynamic>{'type': 'none', 'request': null},
'acceptProxyProtocol': null
};
if (headerType == 'http') {
streamSetting['tcpSettings']['header']['type'] = 'http';
if (host != '' || path != '') {
streamSetting['tcpSettings']['header']['request'] = {
'path': path == null ? ['/'] : path.split(','),
'headers': {
'Host': host == null ? '' : host.split(','),
'User-Agent': [
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36',
'Mozilla/5.0 (iPhone; CPU iPhone OS 10_0_2 like Mac OS X) AppleWebKit/601.1 (KHTML, like Gecko) CriOS/53.0.2785.109 Mobile/14A456 Safari/601.1.46',
],
'Accept-Encoding': [
'gzip, deflate',
],
'Connection': [
'keep-alive',
],
'Pragma': 'no-cache',
},
'version': '1.1',
'method': 'GET',
};
sni = streamSetting['tcpSettings']['header']['request']['headers']
['Host']
.length >
0
? streamSetting['tcpSettings']['header']['request']['headers']
['Host'][0]
: sni;
}
} else {
streamSetting['tcpSettings']['header']['type'] = 'none';
sni = host != '' ? host ?? '' : '';
}
} else if (transport == 'kcp') {
streamSetting['kcpSettings'] = {
'mtu': 1350,
'tti': 50,
'uplinkCapacity': 12,
'downlinkCapacity': 100,
'congestion': false,
'readBufferSize': 1,
'writeBufferSize': 1,
'header': {
'type': headerType ?? 'none',
},
'seed': (seed == null || seed == '') ? null : seed,
};
} else if (transport == 'ws') {
streamSetting['wsSettings'] = {
'path': path ?? ['/'],
'headers': {'Host': host ?? ''},
'maxEarlyData': null,
'useBrowserForwarding': null,
'acceptProxyProtocol': null,
};
sni = streamSetting['wsSettings']['headers']['Host'];
} else if (transport == 'h2' || transport == 'http') {
streamSetting['network'] = 'h2';
streamSetting['h2Setting'] = {
'host': host?.split(',') ?? '',
'path': path ?? ['/'],
};
sni = streamSetting['h2Setting']['host'].length > 0
? streamSetting['h2Setting']['host'][0]
: sni;
} else if (transport == 'quic') {
streamSetting['quicSettings'] = {
'security': quicSecurity ?? 'none',
'key': key ?? '',
'header': {'type': headerType ?? 'none'},
};
} else if (transport == 'grpc') {
streamSetting['grpcSettings'] = {
'serviceName': serviceName ?? '',
'multiMode': mode == 'multi',
};
sni = host ?? '';
}
return sni;
}