Put sockname to credentials (#2532)

* Add sockname to credentials

* Explicit credentials type define
This commit is contained in:
JianBo He 2019-05-14 10:22:30 +08:00 committed by GitHub
parent 97cca1a5ba
commit 79c1b7eb78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 6 deletions

View File

@ -40,6 +40,7 @@
-record(pstate, { -record(pstate, {
zone, zone,
sendfun, sendfun,
sockname,
peername, peername,
peercert, peercert,
proto_ver, proto_ver,
@ -87,12 +88,14 @@
%%------------------------------------------------------------------------------ %%------------------------------------------------------------------------------
-spec(init(map(), list()) -> state()). -spec(init(map(), list()) -> state()).
init(SocketOpts = #{ peername := Peername init(SocketOpts = #{ sockname := Sockname
, peername := Peername
, peercert := Peercert , peercert := Peercert
, sendfun := SendFun}, Options) -> , sendfun := SendFun}, Options) ->
Zone = proplists:get_value(zone, Options), Zone = proplists:get_value(zone, Options),
#pstate{zone = Zone, #pstate{zone = Zone,
sendfun = SendFun, sendfun = SendFun,
sockname = Sockname,
peername = Peername, peername = Peername,
peercert = Peercert, peercert = Peercert,
proto_ver = ?MQTT_PROTO_V4, proto_ver = ?MQTT_PROTO_V4,
@ -208,11 +211,13 @@ client_id(#pstate{client_id = ClientId}) ->
credentials(#pstate{zone = Zone, credentials(#pstate{zone = Zone,
client_id = ClientId, client_id = ClientId,
username = Username, username = Username,
sockname = Sockname,
peername = Peername, peername = Peername,
peercert = Peercert, peercert = Peercert,
ws_cookie = WsCookie}) -> ws_cookie = WsCookie}) ->
with_cert(#{zone => Zone, with_cert(#{zone => Zone,
client_id => ClientId, client_id => ClientId,
sockname => Sockname,
username => Username, username => Username,
peername => Peername, peername => Peername,
ws_cookie => WsCookie, ws_cookie => WsCookie,

View File

@ -80,11 +80,15 @@
| banned | banned
| bad_authentication_method). | bad_authentication_method).
-type(protocol() :: mqtt | 'mqtt-sn' | coap | stomp | none | atom()). -type(protocol() :: mqtt | 'mqtt-sn' | coap | stomp | none | atom()).
-type(credentials() :: #{client_id := client_id(), -type(credentials() :: #{zone := zone(),
username := username(), client_id := client_id(),
peername := peername(), username := username(),
auth_result := auth_result(), sockname := peername(),
zone => zone(), peername := peername(),
ws_cookie := undefined | list(),
mountpoint := binary(),
password => binary(),
auth_result => auth_result(),
atom() => term() atom() => term()
}). }).
-type(subscription() :: #subscription{}). -type(subscription() :: #subscription{}).