created mirror

This commit is contained in:
whatever
2026-09-14 20:19:29 -04:00
commit 6764738d92
600 changed files with 87187 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
/*
Action.java
*
* You may use and distribute under the terms of either the GNU Lesser
* General Public License, either version 2 of the license or,
* at your choice, any later version. Alternatively, you may use and
* distribute under the terms of the XPL.
*
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
* the licenses.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README
* file for more details.
*
*/
/*
* Written by Antti-Juhani Kaijanaho
*/
package org.gzigzag.ztp.client;
public interface Action {
String name();
boolean needSession();
void action(RemotePieceData rpd, Session ses);
}

View File

@@ -0,0 +1,43 @@
/*
Get.java
*
* You may use and distribute under the terms of either the GNU Lesser
* General Public License, either version 2 of the license or,
* at your choice, any later version. Alternatively, you may use and
* distribute under the terms of the XPL.
*
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
* the licenses.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README
* file for more details.
*
*/
/*
* Written by Antti-Juhani Kaijanaho
*/
package org.gzigzag.ztp.client;
import org.gzigzag.ztp.*;
import org.gzigzag.*;
import java.io.*;
import java.util.*;
public class Get implements Action {
public String name() { return "GET"; }
public boolean needSession() { return true; }
public void action(RemotePieceData rpd, Session ses) {
try {
ses.get(rpd.subspaceName, rpd.subspace);
} catch (IOException e) {
throw new ZZError("" + e);
}
}
}

View File

@@ -0,0 +1,43 @@
/*
Put.java
*
* You may use and distribute under the terms of either the GNU Lesser
* General Public License, either version 2 of the license or,
* at your choice, any later version. Alternatively, you may use and
* distribute under the terms of the XPL.
*
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
* the licenses.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README
* file for more details.
*
*/
/*
* Written by Antti-Juhani Kaijanaho
*/
package org.gzigzag.ztp.client;
import org.gzigzag.ztp.*;
import org.gzigzag.*;
import java.io.*;
import java.util.*;
public class Put implements Action {
public String name() { return "PUT"; }
public boolean needSession() { return true; }
public void action(RemotePieceData rpd, Session ses) {
if (rpd.subspace == null) throw new ZZError("there's nothing to put!");
Subspace ss = new Subspace(rpd.subspace.s("d.ztp-subspace"));
try {
ses.put(rpd.subspaceName, ss.getCells(), ss.getSoftDims());
} catch (IOException e) {
throw new ZZError("" + e);
}
}
}

View File

@@ -0,0 +1,64 @@
/*
RemotePieceData.zob
*
* You may use and distribute under the terms of either the GNU Lesser
* General Public License, either version 2 of the license or,
* at your choice, any later version. Alternatively, you may use and
* distribute under the terms of the XPL.
*
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
* the licenses.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README
* file for more details.
*
*/
/*
* Written by Antti-Juhani Kaijanaho
*/
package org.gzigzag.ztp.client;
import org.gzigzag.*;
public class RemotePieceData implements ZOb {
public static boolean dbg = false;
private static void p(String s) { if(dbg) ZZLogger.log(s); }
private static void pa(String s) { ZZLogger.log(s); }
STRUCTPARAMS {
/** Server FQDN. */
String serverFQDN = null;
/** Server port. */
int serverPort = -1;
/** User name. */
String userName = null;
/** User password. */
String userPassword = null;
/** Subspace name. */
String subspaceName = "ALL";
/** Subspace handle. */
ZZCell subspace = null;
}
INITIALIZE {
if (serverFQDN == null) throw new ZZError("need server FQDN");
if (serverPort == -1) throw new ZZError("need server port");
if (userName == null) throw new ZZError("need a user name");
if (subspaceName == null) throw new ZZError("need a subspace name");
p("serverFQDN = " + serverFQDN);
p("serverPort = " + serverPort);
p("userName = " + userName);
p("userPassword = " + userPassword);
p("subspaceName = " + subspaceName);
p("subspace = " + subspace);
}
}

View File

@@ -0,0 +1,76 @@
/*
Session.java
*
* You may use and distribute under the terms of either the GNU Lesser
* General Public License, either version 2 of the license or,
* at your choice, any later version. Alternatively, you may use and
* distribute under the terms of the XPL.
*
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
* the licenses.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README
* file for more details.
*
*/
/*
* Written by Antti-Juhani Kaijanaho
*/
package org.gzigzag.ztp.client;
import org.gzigzag.*;
import org.gzigzag.ztp.*;
class Response {
public static boolean dbg = false;
private static void p(String s) { if(dbg) ZZLogger.log("[" + s + "]"); }
private static void pa(String s) { ZZLogger.log(s); }
public int major;
public int minor;
public int ident;
// Major codes
public final static int positivePreliminary = 1;
public final static int positiveCompletion = 2;
public final static int positiveIntermediate = 3;
public final static int transientNegativeCompletion = 4;
public final static int permanentNegativeCompletion = 5;
// Minor codes
public final static int syntaxCode = 0;
public final static int informationCode = 1;
public final static int connectionCode = 2;
public final static int authenticationCode = 3;
public final static int subspaceCode = 4;
public String explanation;
public Response(String line) {
try {
ZTPCommand.RV r;
r = ZTPCommand.ASCII_number(line);
p("r = " + r);
if (r == null || r.rest.charAt(0) != '.') throw new SyntaxError("bad response line: " + line);
major = Integer.parseInt(r.token);
r = ZTPCommand.ASCII_number(r.rest.substring(1));
p("r = " + r);
if (r == null || r.rest.charAt(0) != '.') throw new SyntaxError("bad response line: " + line);
minor = Integer.parseInt(r.token);
r = ZTPCommand.ASCII_number(r.rest.substring(1));
p("r = " + r);
if (r == null || r.rest.charAt(0) != ' ') throw new SyntaxError("bad response line: " + line);
ident = Integer.parseInt(r.token);
r = ZTPCommand.lwsp(r.rest);
explanation = r.rest;
} catch (NumberFormatException e) {
throw new ZZError("" + e);
}
}
}

View File

@@ -0,0 +1,165 @@
/*
Session.java
*
* You may use and distribute under the terms of either the GNU Lesser
* General Public License, either version 2 of the license or,
* at your choice, any later version. Alternatively, you may use and
* distribute under the terms of the XPL.
*
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
* the licenses.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README
* file for more details.
*
*/
/*
* Written by Antti-Juhani Kaijanaho
*/
package org.gzigzag.ztp.client;
import org.gzigzag.*;
import org.gzigzag.ztp.*;
import java.net.*;
import java.io.*;
import java.util.*;
public class Session implements SafeExit.Cleanupable {
private String server;
private Socket sock;
private int port;
private LineBufferedIO io;
public Session(String server, int port) throws UnknownHostException {
this.server = server;
this.port = port;
try {
sock = new Socket(server, port);
io = new LineBufferedIO(sock.getInputStream(), sock.getOutputStream());
String line = io.readline();
Response resp = new Response(line);
if (resp.major != Response.positiveCompletion) {
sock.close();
throw new ZZError("no response from server");
}
} catch (IOException e) {
throw new ZZError("" + e);
}
SafeExit.registerObject(this);
}
/** Login to server. If passwd is null, attempt
* preauthentication. */
public void login(String username, String passwd) throws IOException {
if (passwd == null) {
io.writeln("AUTH/PRE " + ZTPCommand.encode(username));
} else {
io.writeln("AUTH/PASS " + ZTPCommand.encode(username)
+ " " + ZTPCommand.encode(passwd));
}
Response resp = new Response(io.readline());
if (resp.major != Response.positiveCompletion) {
throw new ZZError("Unable to login: " + resp.explanation);
}
}
public void close() throws IOException {
io.writeln("QUIT");
io.readline();
sock.close();
SafeExit.unregisterObject(this);
}
public void cleanup() throws Throwable {
io.writeln("A");
io.readline();
io.writeln("QUIT");
io.readline();
sock.close();
}
public void put(String subspace, Enumeration cells, String[] sdims) throws IOException {
io.writeln("PUT " + ZTPCommand.encode(subspace));
Response res = new Response(io.readline());
if (res.major != Response.positiveIntermediate) {
throw new ZZError("unable to put: " + res.explanation);
}
SubspaceDump.dump(io, cells, sdims, "");
res = new Response(io.readline());
if (res.major != Response.positiveCompletion) {
throw new ZZError("failed to put: " + res.explanation);
}
}
public void get(String subspace, ZZCell basecell) throws IOException {
io.writeln("GET " + ZTPCommand.encode(subspace));
Response res = new Response(io.readline());
if (res.major != Response.positiveIntermediate) {
throw new ZZError("unable to get: " + res.explanation);
}
SubspaceDump sd;
try {
sd = new SubspaceDump(io);
} finally {
res = new Response(io.readline());
if (res.major != Response.positiveCompletion) {
throw new ZZError("failed to get: " + res.explanation);
}
}
// Delete the old subspace
if (basecell != null && basecell.s("d.ztp-subspace") != null) {
Subspace ss = new Subspace(basecell.s("d.ztp-subspace"));
String[] sdims = ss.getSoftDims();
for (Enumeration e = ss.getCells(); e.hasMoreElements();) {
ZZCell c = (ZZCell)e.nextElement();
for (int i = 0; i < sdims.length; i++) {
if (c.s(sdims[i], 1) != null) c.disconnect(sdims[i], 1);
if (c.s(sdims[i], -1) != null) c.disconnect(sdims[i], -1);
}
if (c.s("d.ztp-subspace", 1) != null) c.disconnect("d.ztp-subspace", 1);
if (c.s("d.ztp-subspace", -1) != null) c.disconnect("d.ztp-subspace", -1);
}
}
ZZDimSpace space = (ZZDimSpace)basecell.getSpace();
// Create the new subspace
{
ZZCell oc = basecell;
for (Enumeration e = sd.cellids.keys(); e.hasMoreElements();) {
String s = (String)e.nextElement();
ZZCell c = space.getCellByID(s);
oc.connect("d.ztp-subspace", 1, c);
oc = c;
}
}
for (Enumeration e = sd.content.keys(); e.hasMoreElements();) {
String s = (String)e.nextElement();
ZZCell c = space.getCellByID(s);
c.setText((String)sd.content.get(s));
}
for (Enumeration e = sd.dims.keys(); e.hasMoreElements();) {
String dimname = (String)e.nextElement();
Hashtable dim = (Hashtable)sd.dims.get(dimname);
space.d(dimname);
for (Enumeration f = dim.keys(); f.hasMoreElements();) {
String s1 = (String)f.nextElement();
String s2 = (String)dim.get(s1);
ZZCell c1 = space.getCellByID(s1);
ZZCell c2 = space.getCellByID(s2);
c1.connect(dimname, c2);
}
}
}
}

View File

@@ -0,0 +1,76 @@
/*
Put.java
*
* You may use and distribute under the terms of either the GNU Lesser
* General Public License, either version 2 of the license or,
* at your choice, any later version. Alternatively, you may use and
* distribute under the terms of the XPL.
*
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
* the licenses.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README
* file for more details.
*
*/
/*
* Written by Antti-Juhani Kaijanaho
*/
package org.gzigzag.ztp.client;
import org.gzigzag.ztp.*;
import org.gzigzag.*;
import java.util.*;
class Subspace {
private String[] sdims;
private Hashtable cells = new Hashtable();
public String[] getSoftDims() { return sdims; }
public Enumeration getCells() { return cells.keys(); }
public Subspace(ZZCell base) {
String[] origdims = base.getSpace().dims();
Vector dimv = new Vector();
for (int i = 0; i < origdims.length; i++) {
if (origdims[i].equals("d.ztp-subspace")
|| origdims[i].equals("d.cellcreation")) {
continue;
}
dimv.addElement(origdims[i]);
}
sdims = new String[dimv.size()];
for (int i = 0; i < sdims.length; i++) {
sdims[i] = (String)dimv.elementAt(i);
}
if (base == null) return;
Stack stack = new Stack();
stack.push(base);
Hashtable seen = new Hashtable();
while (!stack.empty()) {
ZZCell c = (ZZCell)stack.pop();
for (int i = 0; i < sdims.length; i++) {
ZZCell d = c.s(sdims[i], 1);
if (d != null && !seen.containsKey(d)) {
stack.push(d);
seen.put(d, d);
}
d = c.s(sdims[i], -1);
if (d != null && !seen.containsKey(d)) {
stack.push(d);
seen.put(d, d);
}
}
cells.put(c, c);
}
}
}