22
33import com .v2soft .styxlib .exceptions .StyxErrorMessageException ;
44import com .v2soft .styxlib .exceptions .StyxException ;
5+ import com .v2soft .styxlib .exceptions .StyxNotAuthorizedException ;
6+ import com .v2soft .styxlib .exceptions .StyxUnknownClientIdException ;
57import com .v2soft .styxlib .l5 .enums .MessageType ;
68import com .v2soft .styxlib .l5 .messages .*;
79import com .v2soft .styxlib .l5 .messages .base .StyxMessage ;
810import com .v2soft .styxlib .l5 .messages .base .StyxTMessageFID ;
911import com .v2soft .styxlib .l5 .structs .StyxQID ;
1012import com .v2soft .styxlib .l6 .vfs .IVirtualStyxFile ;
1113import com .v2soft .styxlib .library .types .ConnectionDetails ;
12- import com .v2soft .styxlib .library .types .Credentials ;
13- import com .v2soft .styxlib .library .types .impl .CredentialsImpl ;
1414import com .v2soft .styxlib .server .ClientsRepo ;
1515import com .v2soft .styxlib .l5 .dev .MetricsAndStats ;
1616
@@ -109,33 +109,41 @@ public void processPacket(StyxMessage message, int clientId) throws StyxExceptio
109109 answer = e .getErrorMessage ();
110110 answer .setTag (message .getTag ());
111111 mErrorPackets ++;
112+ } catch (StyxNotAuthorizedException e ) {
113+ answer = new StyxRErrorMessage (message .getTag (), "Not authorized" );
114+ mErrorPackets ++;
115+ } catch (StyxUnknownClientIdException e ) {
116+ answer = new StyxRErrorMessage (message .getTag (), "Unknown client ID, try to reconnect" );
117+ mErrorPackets ++;
118+ } catch (StyxException e ) {
119+ answer = new StyxRErrorMessage (message .getTag (), e .getMessage ());
120+ mErrorPackets ++;
112121 }
113122 if (answer != null ) {
114123 mAnswerPackets ++;
115124 mClientsRepo .getDriver (clientId ).sendMessage (answer , clientId , 0 );
116125 }
117126 }
118127
119- private StyxRAttachMessage processAttach (int clientId , StyxTAttachMessage msg ) {
120- Credentials credentials = new CredentialsImpl (msg .getUserName (), null );
128+ private StyxRAttachMessage processAttach (int clientId , StyxTAttachMessage msg ) throws StyxUnknownClientIdException {
121129 var clientDetails = mClientsRepo .getClient (clientId );
122- clientDetails .setCredentials ( credentials );
123- String mountPoint = msg .getMountPoint () ;
130+ clientDetails .setUsername ( msg . userName );
131+ String mountPoint = msg .mountPoint ;
124132 mRoot .onConnectionOpened (clientId );
125133 IVirtualStyxFile root = mRoot ; // TODO .getDirectory(mountPoint); there should be some logic with mountPoint?
126134 StyxRAttachMessage answer = new StyxRAttachMessage (msg .getTag (), root .getQID ());
127135 clientDetails .registerOpenedFile (msg .getFID (), root );
128136 return answer ;
129137 }
130138
131- private StyxMessage processAuth (int clientId , StyxTAuthMessage msg ) {
132- Credentials credentials = new CredentialsImpl (msg .getUserName (), null );
133- mClientsRepo .getClient (clientId ).setCredentials (credentials );
139+ private StyxMessage processAuth (int clientId , StyxTAuthMessage msg ) throws StyxUnknownClientIdException {
140+ mClientsRepo .getClient (clientId ).setUsername (msg .mUserName );
134141 // TODO handle auth packet
135142 return new StyxRAuthMessage (msg .getTag (), StyxQID .EMPTY );
136143 }
137144
138- private StyxMessage processClunk (int clientId , StyxTMessageFID msg ) throws StyxErrorMessageException {
145+ private StyxMessage processClunk (int clientId , StyxTMessageFID msg )
146+ throws StyxException {
139147 mClientsRepo .closeFile (clientId , msg .getFID ());
140148 return new StyxMessage (MessageType .Rclunk , msg .getTag ());
141149 }
@@ -144,7 +152,8 @@ private StyxMessage processWalk(int clientId, StyxTWalkMessage msg) throws StyxE
144152 long fid = msg .getFID ();
145153 final List <StyxQID > qidsList = new LinkedList <StyxQID >();
146154 final IVirtualStyxFile walkFile = mClientsRepo .getAssignedFile (clientId , fid ).walk (
147- msg .getPathElements ().iterator (),
155+ clientId ,
156+ new LinkedList <>(msg .getPathElements ()),
148157 qidsList );
149158 if (walkFile != null ) {
150159 mClientsRepo .getClient (clientId ).registerOpenedFile (msg .getNewFID (), walkFile );
@@ -159,7 +168,7 @@ private StyxMessage processOpen(int clientId, StyxTOpenMessage msg)
159168 throws StyxException {
160169 long fid = msg .getFID ();
161170 IVirtualStyxFile file = mClientsRepo .getAssignedFile (clientId , fid );
162- if (file .open (clientId , msg .getMode () )) {
171+ if (file .open (clientId , msg .mode )) {
163172 return new StyxROpenMessage (msg .getTag (), file .getQID (),
164173 mConnectionDetails .ioUnit () - DEFAULT_PACKET_HEADER_SIZE , false );
165174 } else {
@@ -168,7 +177,7 @@ private StyxMessage processOpen(int clientId, StyxTOpenMessage msg)
168177 }
169178
170179 private StyxMessage processRemove (int clientId , StyxTMessageFID msg )
171- throws StyxErrorMessageException {
180+ throws StyxException {
172181 if (mClientsRepo .getAssignedFile (clientId , msg .getFID ()).delete (clientId )) {
173182 return new StyxMessage (MessageType .Rremove , msg .getTag ());
174183 } else {
@@ -177,9 +186,9 @@ private StyxMessage processRemove(int clientId, StyxTMessageFID msg)
177186 }
178187
179188 private StyxMessage processCreate (int clientId , StyxTCreateMessage msg )
180- throws StyxErrorMessageException {
189+ throws StyxException {
181190 final IVirtualStyxFile file = mClientsRepo .getAssignedFile (clientId , msg .getFID ());
182- StyxQID qid = file .create (msg .getName () , msg .getPermissions () , msg .getMode () );
191+ StyxQID qid = file .create (clientId , msg .name , msg .permissions , msg .mode );
183192 return new StyxROpenMessage (msg .getTag (), qid , mConnectionDetails .ioUnit (), true );
184193 }
185194
@@ -188,23 +197,23 @@ private StyxMessage processWStat(StyxTWStatMessage msg) {
188197 return new StyxMessage (MessageType .Rwstat , msg .getTag ());
189198 }
190199
191- private StyxMessage processWrite (int clientId , StyxTWriteMessage msg ) throws StyxErrorMessageException {
200+ private StyxMessage processWrite (int clientId , StyxTWriteMessage msg ) throws StyxException {
192201 long fid = msg .getFID ();
193202 return new StyxRWriteMessage (msg .getTag (),
194- mClientsRepo .getAssignedFile (clientId , fid ).write (clientId , msg .getData () , msg .getOffset () ));
203+ mClientsRepo .getAssignedFile (clientId , fid ).write (clientId , msg .data , msg .offset ));
195204 }
196205
197- private StyxMessage processRead (int clientId , StyxTReadMessage msg ) throws StyxErrorMessageException {
198- if (msg .getCount () > mConnectionDetails .ioUnit ()) {
206+ private StyxMessage processRead (int clientId , StyxTReadMessage msg ) throws StyxException {
207+ if (msg .count > mConnectionDetails .ioUnit ()) {
199208 return new StyxRErrorMessage (msg .getTag (), "IOUnit overflow" );
200209 }
201210 long fid = msg .getFID ();
202- byte [] buffer = new byte [(int ) msg .getCount () ];
211+ byte [] buffer = new byte [(int ) msg .count ];
203212 MetricsAndStats .byteArrayAllocationRRead ++;
204213 return new StyxRReadMessage (msg .getTag (), buffer ,
205- ( int ) mClientsRepo
214+ mClientsRepo
206215 .getAssignedFile (clientId , fid )
207- .read (clientId , buffer , msg .getOffset () , msg .getCount () ));
216+ .read (clientId , buffer , msg .offset , msg .count ));
208217 }
209218
210219 public IVirtualStyxFile getRoot () {
0 commit comments